From ea11dc0ec81c40a1f18f3975895389273e87bff2 Mon Sep 17 00:00:00 2001 From: willem Date: Thu, 2 May 2024 07:19:30 +0200 Subject: [PATCH] blocks --- 42100/lego4200_top_blocks.py | 19 +++++++++++++++++++ 42100/lego42100_bot_blocks.py | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 42100/lego4200_top_blocks.py create mode 100644 42100/lego42100_bot_blocks.py diff --git a/42100/lego4200_top_blocks.py b/42100/lego4200_top_blocks.py new file mode 100644 index 0000000..e705b30 --- /dev/null +++ b/42100/lego4200_top_blocks.py @@ -0,0 +1,19 @@ +# pybricks blocks file:{"blocks":{"languageVersion":0,"blocks":[{"type":"blockGlobalSetup","id":"bjK,wS1MYO7aiYkFSwd{","x":150,"y":100,"deletable":false,"next":{"block":{"type":"variables_set_technic_hub","id":"JA1+memdZuJ,}9_?Fe.X","extraState":{"optionLevel":2},"fields":{"VAR":{"id":"JT)}wNv,XYr)|5sh{qx{"},"FIELDBROADCAST":1},"inputs":{"AXIS_TOP":{"shadow":{"type":"blockParametersAxis","id":"wW|b)/k#MohULL6w]Y~l","fields":{"VALUE":"z"}}},"AXIS_FRONT":{"shadow":{"type":"blockParametersAxis","id":"0u-nPN8%|sCgagoUOi/k","fields":{"VALUE":"x"}}}},"next":{"block":{"type":"variables_set_xbox_controller","id":"a{]tN%LVp!tU)tWgPY4s","fields":{"VAR":{"id":"c3ZPftI,+wIw}F9{dDN)"}},"next":{"block":{"type":"variables_set_motor","id":"@lzwaJ02@AD=~Y[0~#wP","fields":{"VAR":{"id":";u=:77z%N%A}+#nV5^m("}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"*u]jbgaP9xl;K.$J^*Ya","fields":{"NAME":"A"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"@riF*dku2/UKLZIE*[:z","fields":{"SELECTION":"Direction.CLOCKWISE"}}}},"next":{"block":{"type":"variables_set_motor","id":";wbxfQcwM.af4Jr@^[uS","fields":{"VAR":{"id":"TNOdgE6$~IW6.!VJM2GP"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"BE1[F[c2})J%bDBH-qlp","fields":{"NAME":"B"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"8Dl=}cq#Flx{8][/y)B{","fields":{"SELECTION":"Direction.CLOCKWISE"}}}},"next":{"block":{"type":"variables_set_motor","id":"tzEd(smhG{l8q=Ia?uGN","fields":{"VAR":{"id":"BIfO|W3=;$H^yn]MSe[6"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"X6^mLwSuNb`;PDbPWrU;","fields":{"NAME":"C"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"G@6f7zrY_)3xuu,{pl~a","fields":{"SELECTION":"Direction.CLOCKWISE"}}}},"next":{"block":{"type":"variables_set_motor","id":"lZ6Mwck7iJ/1]$pLNC7.","fields":{"VAR":{"id":"N)N6m(tf+)HThENwsjAu"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"!##Mwj:fRii}S$5^5T?T","fields":{"NAME":"D"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"98h387kMi:wk)t_==rA:","fields":{"SELECTION":"Direction.CLOCKWISE"}}}}}}}}}}}}}}}}},{"type":"blockGlobalStart","id":"3tJe|AWl0baN(wH9a$@.","x":162,"y":502,"deletable":false,"next":{"block":{"type":"blockPrint","id":"j,,T}?rBkaW$1v?olp4p","extraState":{"optionLevel":0},"inputs":{"TEXT0":{"shadow":{"type":"text","id":"!x5.0YiWya^`(y)yO5B8","fields":{"TEXT":"Hello, Pybricks!"}}}},"next":{"block":{"type":"blockFlowWhile","id":"WJ4_+S?d{Zuj]G_N+E*k","fields":{"MODE":"WHILE"},"inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"=u|+SAYJ^g43S^{~bB1l"}},"DO":{"block":{"type":"blockBleBroadcast","id":"9Vwyz6;4qclr:O4dO.wx","inputs":{"VAR":{"shadow":{"type":"variables_get_ble_hub","id":"V+v,vJle+_3,]J!%HT[Z","fields":{"VAR":{"id":"JT)}wNv,XYr)|5sh{qx{","name":"top_hub","type":"TechnicHub"}}}},"VALUE0":{"shadow":{"type":"blockMathNumber","id":"(?ZP/=[5cc^-N43$z@[M","fields":{"NUM":0}},"block":{"type":"blockListCreate","id":"x+:MEA,${M~Ir%QG20O{","extraState":{"optionLevel":4},"inputs":{"ADD0":{"shadow":{"type":"blockMathNumber","id":"a+HZ{[-P80-TJLyaf2tt","fields":{"NUM":0}},"block":{"type":"blockJoystickValue","id":"0!l~u=H}RSWmzZl.zM6$","fields":{"JOYSTICK":"XBOX_LT"},"inputs":{"VAR":{"shadow":{"type":"variables_get_gamepad","id":"rU}oS6rmN*@W4=`}}rmt","fields":{"VAR":{"id":"c3ZPftI,+wIw}F9{dDN)","name":"controller","type":"XboxController"}}}}}}},"ADD1":{"shadow":{"type":"blockMathNumber","id":"V5v;6=I_hgxFaZzG,xh4","fields":{"NUM":0}},"block":{"type":"blockJoystickValue","id":"0~Twk)tX;4)`AI78RAp_","fields":{"JOYSTICK":"XBOX_RT"},"inputs":{"VAR":{"shadow":{"type":"variables_get_gamepad","id":"RNq%0!weXri-,zR$Aa.l","fields":{"VAR":{"id":"c3ZPftI,+wIw}F9{dDN)","name":"controller","type":"XboxController"}}}}}}},"ADD2":{"shadow":{"type":"blockMathNumber","id":"PoKdKE`[fli|41~l_.B}","fields":{"NUM":0}},"block":{"type":"blockJoystickValue","id":"v5K)W[)|a-CimmW.T4[b","fields":{"JOYSTICK":"XBOX_LJ_X"},"inputs":{"VAR":{"shadow":{"type":"variables_get_gamepad","id":"+RBN7B9.KNl7H-:lc,}:","fields":{"VAR":{"id":"c3ZPftI,+wIw}F9{dDN)","name":"controller","type":"XboxController"}}}}}}},"ADD3":{"shadow":{"type":"blockMathNumber","id":"M8RMmS.6;CHRa*fep#=4","fields":{"NUM":0}},"block":{"type":"blockJoystickValue","id":"?h(HTeZT%g7`V,]bz/(c","fields":{"JOYSTICK":"XBOX_LJ_Y"},"inputs":{"VAR":{"shadow":{"type":"variables_get_gamepad","id":"gy%o8nW==mVXWWZ9oTun","fields":{"VAR":{"id":"c3ZPftI,+wIw}F9{dDN)","name":"controller","type":"XboxController"}}}}}}}}}}}}}}}}}}}]},"variables":[{"name":"red","id":"b(K72kbjLK3eaWY0rZ|H","type":"ColorDef"},{"name":"orange","id":"c5QKn-VxQXjXw0PEXW{$","type":"ColorDef"},{"name":"yellow","id":"J2n}pzD-+3vRNACoH}A|","type":"ColorDef"},{"name":"green","id":"0(NPnGB8B#2Qj*3dMqMj","type":"ColorDef"},{"name":"cyan","id":"`cTjOq2c5Qt!:AB0MNE~","type":"ColorDef"},{"name":"blue","id":")~d23yr%3gimljv:M!%H","type":"ColorDef"},{"name":"violet","id":".;6s97*6~~o){?kf32Vu","type":"ColorDef"},{"name":"magenta","id":"hnOw;Pff:#:!OejeEBQ8","type":"ColorDef"},{"name":"white","id":"|u=R}I%9QzW(~|dUY+U}","type":"ColorDef"},{"name":"none","id":"*c=-CgnIE*K6T9Gxk[8}","type":"ColorDef"},{"name":"top_hub","id":"JT)}wNv,XYr)|5sh{qx{","type":"TechnicHub"},{"name":"controller","id":"c3ZPftI,+wIw}F9{dDN)","type":"XboxController"},{"name":"Boom_motor","id":";u=:77z%N%A}+#nV5^m(","type":"Motor"},{"name":"arm_motor","id":"TNOdgE6$~IW6.!VJM2GP","type":"Motor"},{"name":"Bucket_motor","id":"BIfO|W3=;$H^yn]MSe[6","type":"Motor"},{"name":"Scoop_motor","id":"N)N6m(tf+)HThENwsjAu","type":"Motor"}],"info":{"type":"pybricks","version":"1.2.2"}} +from pybricks.hubs import TechnicHub +from pybricks.iodevices import XboxController +from pybricks.parameters import Axis, Direction, Port +from pybricks.pupdevices import Motor + +# Set up all devices. +top_hub = TechnicHub(top_side=Axis.Z, front_side=Axis.X, broadcast_channel=1) +Boom_motor = Motor(Port.A, Direction.CLOCKWISE) +arm_motor = Motor(Port.B, Direction.CLOCKWISE) +Bucket_motor = Motor(Port.C, Direction.CLOCKWISE) +Scoop_motor = Motor(Port.D, Direction.CLOCKWISE) +controller = XboxController() + + +# The main program starts here. +print('Hello, Pybricks!') +while True: + top_hub.ble.broadcast([controller.triggers()[0], controller.triggers()[1], controller.joystick_left()[0], controller.joystick_left()[1]]) diff --git a/42100/lego42100_bot_blocks.py b/42100/lego42100_bot_blocks.py new file mode 100644 index 0000000..e37f15b --- /dev/null +++ b/42100/lego42100_bot_blocks.py @@ -0,0 +1,22 @@ +# pybricks blocks file:{"blocks":{"languageVersion":0,"blocks":[{"type":"blockGlobalSetup","id":"bjK,wS1MYO7aiYkFSwd{","x":150,"y":100,"deletable":false,"next":{"block":{"type":"variables_set_technic_hub","id":"CDp2C5~8v-U[5-,}t0x`","extraState":{"optionLevel":3},"fields":{"VAR":{"id":".qW5|.{lJTGrt0ogrew^"},"FIELDBROADCAST":0,"FIELDOBSERVE0":1},"inputs":{"AXIS_TOP":{"shadow":{"type":"blockParametersAxis","id":"%3.s1+V/VE66hRqhGgX`","fields":{"VALUE":"z"}}},"AXIS_FRONT":{"shadow":{"type":"blockParametersAxis","id":"Q7nA5!1=|XRI44Xtdd,1","fields":{"VALUE":"x"}}}},"next":{"block":{"type":"variables_set_motor","id":"ANjT,T}UOCFkaPuj!E^|","fields":{"VAR":{"id":"n74#}[-5,:EfDSbW1`Eo"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"=@8O}nLT/A+}{/vm4rdE","fields":{"NAME":"D"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"X~R6~l8[$6}pizerd2QN","fields":{"SELECTION":"Direction.CLOCKWISE"}}}},"next":{"block":{"type":"variables_set_motor","id":"sAvR(D|kYm:Tw]v6,)Vg","fields":{"VAR":{"id":"ms+~*r]DdB]t^hq]?5.o"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"e=JcAz_R[T)`tlCqB`Id","fields":{"NAME":"A"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"LaN8|(C`BE1URNl4dedy","fields":{"SELECTION":"Direction.CLOCKWISE"}}}},"next":{"block":{"type":"variables_set_motor","id":"lZfmaD=4j]Vq{V]UlmO|","fields":{"VAR":{"id":"8)(~;Fi,SuJk[~Rf%bO5"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"y~J`U(CFq7f(Yt!Y)Gdp","fields":{"NAME":"B"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"G=Yj5$KuFP7K2nS%{]Vj","fields":{"SELECTION":"Direction.COUNTERCLOCKWISE"}}}},"next":{"block":{"type":"variables_setup_any","id":"*{F2T}Bb.@RqxP-zY.fL","fields":{"VAR":{"id":"qx7)XWPn2R#;6.#lCF93"}},"inputs":{"VALUE0":{"shadow":{"type":"blockMathNumber","id":"iAJ.py9o7EEhqYQyRzqf","fields":{"NUM":0}}}}}}}}}}}}}}},{"type":"blockGlobalStart","id":"3tJe|AWl0baN(wH9a$@.","x":65,"y":451,"deletable":false,"next":{"block":{"type":"blockFlowWhile","id":"LFn*}]l^+q^KXk{XKjs-","fields":{"MODE":"WHILE"},"inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"]s(zx2#q@Jf)cm}J8cyD"}},"DO":{"block":{"type":"blockVariableSetValue","id":"v=:Wg2#C=k(y~q-za|A#","inputs":{"VAR":{"shadow":{"type":"variables_get_any","id":"uw_@vT,*y}XpxhMbHU}]","fields":{"VAR":{"id":"qx7)XWPn2R#;6.#lCF93","name":"data","type":"Any"}}}},"VALUE0":{"shadow":{"type":"blockMathNumber","id":"2Te~~~@@6X:P+gbaM!de","fields":{"NUM":0}},"block":{"type":"blockBleObserve","id":"JDkxmv+n}-eeEsk]7cQK","fields":{"CHANNEL":"1"},"inputs":{"VAR":{"shadow":{"type":"variables_get_ble_hub","id":"m|eYTJZZ`74yTJmS/oTz","fields":{"VAR":{"id":".qW5|.{lJTGrt0ogrew^","name":"bot_hub","type":"TechnicHub"}}}}}}}},"next":{"block":{"type":"blockIfElse","id":"B1`|Y9bNE[^EO5{;KD;`","extraState":{"optionLevel":1},"inputs":{"IF0":{"shadow":{"type":"blockLogicTrue","id":"vf(z]67+_+FLO!J-{{;N"},"block":{"type":"blockLogicCompare","id":"I74-pQI~zAR-6v^$8G0(","fields":{"OP1":"NEQ"},"inputs":{"A":{"shadow":{"type":"blockMathNumber","id":"-t`-9R1$rrr@*EO9xylt","fields":{"NUM":3}},"block":{"type":"blockVariableGetValue","id":"n~Mh9T|tZ$sHHUz3;%Z@","inputs":{"VAR":{"shadow":{"type":"variables_get_any","id":"h}3O=uD,jKyl{2sr1(iq","fields":{"VAR":{"id":"qx7)XWPn2R#;6.#lCF93","name":"data","type":"Any"}}}}}}},"B":{"shadow":{"type":"blockMathNumber","id":"`mjSN$YHYd71JL7~TozC","fields":{"NUM":4}},"block":{"type":"blockNone","id":"LMbjDR)YoEj2G$QU_lEw"}}}}},"ELSE":{"block":{"type":"blockLightOnColor","id":"qxOGMTb|b7=oXGY?FRH2","extraState":{"optionLevel":1},"fields":{"METHOD":"LIGHT_ON"},"inputs":{"VAR":{"shadow":{"type":"variables_get_color_light_device","id":"{.Yo(r_/U7sM/n9j`Rj|","fields":{"VAR":{"id":".qW5|.{lJTGrt0ogrew^","name":"bot_hub","type":"TechnicHub"}}}},"COLOR":{"shadow":{"type":"variables_get_color","id":"7x]q@QnA?7rS{3;z[7Ss","fields":{"COLOUR":"#ff0000","VAR":{"id":":oqn!2~M3F?@c$t[t-v@","name":"red","type":"ColorDef"}}}}}}}}}}}}}}}}]},"variables":[{"name":"red","id":":oqn!2~M3F?@c$t[t-v@","type":"ColorDef"},{"name":"orange","id":"!Vsb!-U}WIOOVKH3nC55","type":"ColorDef"},{"name":"yellow","id":"n%@V2n^)Mh$@V/n+um-@","type":"ColorDef"},{"name":"green","id":"8;|K/%5TzxP]`BK([1tl","type":"ColorDef"},{"name":"cyan","id":"P_Z[]cHy%{Pt}qh5v[gW","type":"ColorDef"},{"name":"blue","id":"p3vC2DO8lg@onAiZcX9{","type":"ColorDef"},{"name":"violet","id":"?uKxVJ9g~pK2]^/Z.^Op","type":"ColorDef"},{"name":"magenta","id":"3c?e)G]ViW_9_od?pxd+","type":"ColorDef"},{"name":"white","id":"g@3zLA!%73Z!j,GVlbgL","type":"ColorDef"},{"name":"none","id":"p4nf{BI~aSpUZ-dX^XWB","type":"ColorDef"},{"name":"bot_hub","id":".qW5|.{lJTGrt0ogrew^","type":"TechnicHub"},{"name":"superstr_motor","id":"n74#}[-5,:EfDSbW1`Eo","type":"Motor"},{"name":"left_motor","id":"ms+~*r]DdB]t^hq]?5.o","type":"Motor"},{"name":"right_motor","id":"8)(~;Fi,SuJk[~Rf%bO5","type":"Motor"},{"name":"data","id":"qx7)XWPn2R#;6.#lCF93","type":"Any"},{"name":"light","id":"{$tVfD@+QVUYUQIjEaFF","type":"InventorHub"}],"info":{"type":"pybricks","version":"1.2.2"}} +from pybricks.hubs import TechnicHub +from pybricks.parameters import Axis, Color, Direction, Port +from pybricks.pupdevices import Motor + +# Set up all devices. +bot_hub = TechnicHub(top_side=Axis.Z, front_side=Axis.X, broadcast_channel=0, observe_channels=[1]) +superstr_motor = Motor(Port.D, Direction.CLOCKWISE) +left_motor = Motor(Port.A, Direction.CLOCKWISE) +right_motor = Motor(Port.B, Direction.COUNTERCLOCKWISE) + +# Initialize variables. +data = 0 + + +# The main program starts here. +while True: + data = bot_hub.ble.observe(1) + if data != None: + pass + else: + bot_hub.light.on(Color.RED)