In this project, we will show you how to control the LEGO® Technic Cat D11 Bulldozer (42131) with the Powered Up (Train) Remote.

This is a fun way to drive the bulldozer around without having to look at your phone screen all time time. You’ll also use the remote to switch between the functions of the blade, ripper, and ladder.

Driving the LEGO® Technic Cat D11 Bulldozer (42131) with the Powered Up Train Remote.
Driving the LEGO® Technic Cat D11 Bulldozer (42131) with the Powered Up Train Remote.

Requirements

To follow this project, you will need the following:

Understanding the code

The program consists of two main tasks that run in parallel. The first task handles the driving and steering of the bulldozer, as well as powering the function motor.

The second task controls the position of the motor that selects which function is being operated. The details are included as comments in the program below.

When the program begins, it resets the function selector to the zero position, corresponding to the blade up and down movement. You can select any function by pressing the green button along with one of the gray buttons. This will change the remote light and switch the function selector as follows:

  • Left + (blue): Moves the blade up and down.
  • Left − (red): Tilts the blade back and forth.
  • Right + (yellow): Moves the ladder up and down.
  • Right − (green): Moves the ripper up and down.

Once the function is selected, use the red buttons to control the motor that powers the selected function.

Use the gray buttons to control the tracks. You can change the drive acceleration in the main program to a lower value to make the vehicle start and stop driving more gradually. You can also change the speed values corresponding the left and right motor blocks.

This program lets you drive the LEGO® Technic Cat D11 Bulldozer (42131)
  with the Powered Up Remote.
This program lets you drive the LEGO® Technic Cat D11 Bulldozer (42131) with the Powered Up Remote.

Running the Pybricks program

This project uses Pybricks on your LEGO hub. Pybricks makes your creations come alive and helps you unlock the full potential of your LEGO Technic, City, MINDSTORMS, BOOST, or Spike sets.

If you haven’t already, install Pybricks on your hub as shown below, or check out our getting started guide for more details. You can go back to the LEGO firmware and apps at any time.

Install the Pybricks firmware.
settings
install

Now import the program you downloaded earlier, as shown below. Click to connect your hub and ▶ to start!

Import a Pybricks Code project.
files
import
open
connect
run

You can run imported block programs even if you’re not signed up. This is a great way to try out Pybricks and see how it works.

The bulldozer in action

When you’re ready, you can drive the bulldozer as shown below. Make sure to turn on the remote when you start the bulldozer program, so that the hub can find it.

Running it as a Python program

You can also run this project as a Python (MicroPython) program. The following code was generated from the block program above. To run it, create a new empty Python program in Pybricks and copy the code into it.

# pybricks blocks file:{"blocks":{"languageVersion":0,"blocks":[{"type":"blockGlobalSetup","id":"bjK,wS1MYO7aiYkFSwd{","x":-28,"y":360,"deletable":false,"next":{"block":{"type":"variables_set_remote","id":"5(ZHiLt+mTTHOz%vOYOC","extraState":{"optionLevel":0},"fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M"},"METHOD":"CONNECT_ANY"},"next":{"block":{"type":"variables_set_motor","id":"g=O6sK{#.90KNfvnR{3l","fields":{"VAR":{"id":"HB$E(E|0GcK=3:b9OGWK"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"D*][0)m_^se#;]?i?nE~","fields":{"NAME":"A"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"ts6pK}D}12wK?-A7rdcH","fields":{"SELECTION":"Direction.COUNTERCLOCKWISE"}}}},"next":{"block":{"type":"variables_set_motor","id":"$=xhOYJ^ftcYuvA1[:R8","fields":{"VAR":{"id":"WfLWxs!;-+H11Ww!!x:_"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"p!6p@JZi%jsz4X-{UbX)","fields":{"NAME":"B"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"R$^/X.)X.[ug3MtZ.A3H","fields":{"SELECTION":"Direction.CLOCKWISE"}}}},"next":{"block":{"type":"variables_set_motor","id":"$gK`*.B=^D#Sb*GM}@o0","fields":{"VAR":{"id":"9]^QIL#QX=31WQ@/A7^z"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"1=vO3e10f`.G2/~mNPRF","fields":{"NAME":"C"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"Gzy?NnDeNd6;2}DJNrD(","fields":{"SELECTION":"Direction.CLOCKWISE"}}}},"next":{"block":{"type":"variables_set_motor","id":"w7GkS+reB%Y`.G$J%@.1","fields":{"VAR":{"id":"GtM_hctvAF2:Pdx~WV{="}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"=eKu%~uk,.EKZG.a;/b9","fields":{"NAME":"D"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"_s)r!Z|Klq*1J=xg(A8S","fields":{"SELECTION":"Direction.CLOCKWISE"}}}},"next":{"block":{"type":"variables_setup_any","id":"=u+{+^9$B/o{(gX73LKB","fields":{"VAR":{"id":"|:C@ETh=EDU-gt}caTMY"}},"inputs":{"VALUE0":{"shadow":{"type":"blockMathNumber","id":"alqXBx7UGnD02B4+i:CV","fields":{"NUM":0}}}},"next":{"block":{"type":"variables_setup_any","id":"x)*dv{l$cZpN6w.H8+Ua","fields":{"VAR":{"id":"K!78++=(@jb1Q@?p`Xo?"}},"inputs":{"VALUE0":{"shadow":{"type":"blockMathNumber","id":"QUA)4]@v52[zMQoT.e#S","fields":{"NUM":0}}}}}}}}}}}}}}}}}}},{"type":"blockGlobalStart","id":"3tJe|AWl0baN(wH9a$@.","x":-23,"y":924,"deletable":false,"next":{"block":{"type":"blockComment","id":"V!#pkkro!N]8|i+=(q|]","fields":{"FIELDNAME":"This main task will handle driving and the motor\nthat powers (not switches) the function gearbox."},"next":{"block":{"type":"blockMotorConfigure","id":"o50O)HuKH^!kkl75d.j,","extraState":{"optionLevel":1},"fields":{"METHOD":"MOTOR_ACCELERATION"},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"wg.FC*!eHWx@_(P-%!_!","fields":{"VAR":{"id":"HB$E(E|0GcK=3:b9OGWK","name":"left","type":"Motor"}}}},"ARG0":{"shadow":{"type":"unit_angularAcceleration","id":"lqZ6.[N9bi;1K9V!3-3!","fields":{"VALUE0":2500}}}},"next":{"block":{"type":"blockMotorConfigure","id":"B%R0SaiJaG_e,ia$?e]V","extraState":{"optionLevel":1},"fields":{"METHOD":"MOTOR_ACCELERATION"},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"*Zh+cr_B?RHY={P:tuWR","fields":{"VAR":{"id":"WfLWxs!;-+H11Ww!!x:_","name":"right","type":"Motor"}}}},"ARG0":{"shadow":{"type":"unit_angularAcceleration","id":"=_=?hreur#Ke,]1Hm6[^","fields":{"VALUE0":2500}}}},"next":{"block":{"type":"blockFlowWhile","id":")XPU1ML5!B?wjvZX~iqH","fields":{"MODE":"WHILE"},"inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"T+fy{AI.b7k3c!ID([DR"}},"DO":{"block":{"type":"blockIfElse","id":"*{FT(LnDLGFQI)|++xFN","extraState":{"optionLevel":1},"inputs":{"IF0":{"shadow":{"type":"blockLogicTrue","id":"?5=:(zTA=mV2WEb4tqk,"},"block":{"type":"blockButtonIsPressed","id":"~f*}FJ^/-_p;75oCylgz","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":"W,e:auQNt,dyBKikkWju","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"9[fF|(Ou{`s,::B-fP;I","fields":{"VALUE":"CENTER"}}}}}},"DO0":{"block":{"type":"blockComment","id":"1fW+qhE-2Gw%/7BSIu6-","fields":{"FIELDNAME":"If the center button is pressed to change the switch motor,\nwe stop driving and powering the function motor to be safe."},"next":{"block":{"type":"blockMotorStop","id":"3lAgK6zG1A61l}Jnr,Nr","inputs":{"VAR":{"shadow":{"type":"variables_get_simple_motor_device","id":"(69#%{tW!p~9qg?PC5:F","fields":{"VAR":{"id":"HB$E(E|0GcK=3:b9OGWK","name":"left","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"parameters_stop_3","id":"RQ9DBN-G8=RAaR-]R(q$","fields":{"VALUE":"Stop.COAST"}}}},"next":{"block":{"type":"blockMotorStop","id":"R6A.gBv-$?n,BF2NUZM_","inputs":{"VAR":{"shadow":{"type":"variables_get_simple_motor_device","id":"jzh72]Uw9O=Fy~=2;3C!","fields":{"VAR":{"id":"WfLWxs!;-+H11Ww!!x:_","name":"right","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"parameters_stop_3","id":"pO=WD~gP/Fet[9xjxoiH","fields":{"VALUE":"Stop.COAST"}}}},"next":{"block":{"type":"blockMotorStop","id":"-eQf1=QEExaH{NJ5=I5=","inputs":{"VAR":{"shadow":{"type":"variables_get_simple_motor_device","id":"vf9C{VfDWxhA;znkdrMV","fields":{"VAR":{"id":"9]^QIL#QX=31WQ@/A7^z","name":"function","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"parameters_stop_3","id":"mzQ!7QYnXBh:tSVrcsQ4","fields":{"VALUE":"Stop.COAST"}}}}}}}}}}}},"ELSE":{"block":{"type":"blockComment","id":"X+5]`FAANoTE^^|)bdoV","fields":{"FIELDNAME":"Otherwise drive the motors based on the buttons that are pressed."},"next":{"block":{"type":"blockComment","id":"5Bh-a6qu?]*v2l`Wn4PA","fields":{"FIELDNAME":"Use the left/right red buttons for the function motor."},"next":{"block":{"type":"blockIfElse","id":"m[7!gY%:0sA;wz;L`f[f","extraState":{"optionLevel":2},"inputs":{"IF0":{"shadow":{"type":"blockLogicTrue","id":"qPOUxH-_+tQqHLYIeiun"},"block":{"type":"blockButtonIsPressed","id":"x@xXHgbD(0dtC3xF129j","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":"^iw}wvDkvd{lz1towzgD","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"[f0CKh4zgq-GT]%][72J","fields":{"VALUE":"LEFT"}}}}}},"DO0":{"block":{"type":"blockMotorDuty","id":"c!Q.B:wSVsExH+9_yX*y","inputs":{"VAR":{"shadow":{"type":"variables_get_simple_motor_device","id":"drl2O=5U/S`rNET3fSnl","fields":{"VAR":{"id":"9]^QIL#QX=31WQ@/A7^z","name":"function","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"unit_percent","id":"^[KNd7cw+ypX2JJ09ur0","fields":{"VALUE0":100}}}}}},"IF1":{"shadow":{"type":"blockLogicTrue","id":"KkiFi.!:PF,jzHmdfMf4"},"block":{"type":"blockButtonIsPressed","id":"dE5}jm,^cp@wb2_(_9`k","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":"=(hb$G2K}i?`nimF/eYV","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"AYi.q]%In#9B|a1QD7vj","fields":{"VALUE":"RIGHT"}}}}}},"DO1":{"block":{"type":"blockMotorDuty","id":"Z.7z^w1G.4M;Rf`@.T@t","inputs":{"VAR":{"shadow":{"type":"variables_get_simple_motor_device","id":"ZlJeTOG0rEunqM5R-b%m","fields":{"VAR":{"id":"9]^QIL#QX=31WQ@/A7^z","name":"function","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"unit_percent","id":"E[=ozMStgHRJNa?(6awG","fields":{"VALUE0":-100}}}}}},"ELSE":{"block":{"type":"blockMotorStop","id":"}%m%5g$ux7bK0drb=NK]","inputs":{"VAR":{"shadow":{"type":"variables_get_simple_motor_device","id":"4x)i@*nv{k.8hbuVHd+O","fields":{"VAR":{"id":"9]^QIL#QX=31WQ@/A7^z","name":"function","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"parameters_stop_3","id":"q=S.ws:}$|ZgLT*A`mI7","fields":{"VALUE":"Stop.COAST"}}}}}}},"next":{"block":{"type":"blockComment","id":"!K#!17~48wE^*fhi`tJL","fields":{"FIELDNAME":"Use the left +/- for the left track."},"next":{"block":{"type":"blockIfElse","id":"ixTF.]SHL)ilnZT%(=gk","extraState":{"optionLevel":2},"inputs":{"IF0":{"shadow":{"type":"blockLogicTrue","id":"qPOUxH-_+tQqHLYIeiun"},"block":{"type":"blockButtonIsPressed","id":"9eDKjt#r@MtbV?:AO!bG","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":"VLJ.5R;/C+SaRu|@h@.H","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"[=aMJ-h!H(iI/*^?pJ.g","fields":{"VALUE":"LEFT_PLUS"}}}}}},"DO0":{"block":{"type":"blockMotorRun","id":"o?h|jBpWa(+0%;-$p42y","extraState":{"optionLevel":0},"fields":{"METHOD":"MOTOR_RUN_FOREVER"},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"(wesG#=HS=:aKk?!}sJ9","fields":{"VAR":{"id":"HB$E(E|0GcK=3:b9OGWK","name":"left","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"unit_angularVelocity","id":"YLv^6}SMC(hGYh.*Lgqh","fields":{"VALUE0":1000}}}}}},"IF1":{"shadow":{"type":"blockLogicTrue","id":"KkiFi.!:PF,jzHmdfMf4"},"block":{"type":"blockButtonIsPressed","id":"@B(.E-E3_I6^2atJcX`%","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":";T*3nOfBb_@_OT1e@Rnu","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"C-P-3(uM9a,O?dJ=nE?h","fields":{"VALUE":"LEFT_MINUS"}}}}}},"DO1":{"block":{"type":"blockMotorRun","id":"Mj-x)qX)dxbLyUKA+{lL","extraState":{"optionLevel":0},"fields":{"METHOD":"MOTOR_RUN_FOREVER"},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":":_M~X54qEF7_R8,I[PM:","fields":{"VAR":{"id":"HB$E(E|0GcK=3:b9OGWK","name":"left","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"unit_angularVelocity","id":"xoTv]sgw#Lh}X6do_^J9","fields":{"VALUE0":-1000}}}}}},"ELSE":{"block":{"type":"blockMotorStop","id":"(;Cib4g1vI6Z|QlyyAL*","inputs":{"VAR":{"shadow":{"type":"variables_get_simple_motor_device","id":"Tbzhp1+JM`8K1`8M/Je5","fields":{"VAR":{"id":"HB$E(E|0GcK=3:b9OGWK","name":"left","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"parameters_stop_3","id":"g[O;h*V%i@@ARsW,y-zS","fields":{"VALUE":"Stop.COAST"}}}}}}},"next":{"block":{"type":"blockComment","id":"i(xy`IQS=Q4lB#F/ZqoH","fields":{"FIELDNAME":"Use the right +/- for the left track."},"next":{"block":{"type":"blockIfElse","id":"wbyT#t{^epvp[~Eo_Bw%","extraState":{"optionLevel":2},"inputs":{"IF0":{"shadow":{"type":"blockLogicTrue","id":"qPOUxH-_+tQqHLYIeiun"},"block":{"type":"blockButtonIsPressed","id":"=BNh=Dg1}_7t,wzsW[fM","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":"tXq#|4CfC7JHR$K(NHq)","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"OB1O61O=BeBhcMi`{)f5","fields":{"VALUE":"RIGHT_PLUS"}}}}}},"DO0":{"block":{"type":"blockMotorRun","id":"]|Vz%t2~B5N1_v1,KoT0","extraState":{"optionLevel":0},"fields":{"METHOD":"MOTOR_RUN_FOREVER"},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"Ag|3WZjlF.U#~9~~BjC:","fields":{"VAR":{"id":"WfLWxs!;-+H11Ww!!x:_","name":"right","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"unit_angularVelocity","id":"!IVFKnp[_NN*dO4{Ky,D","fields":{"VALUE0":1000}}}}}},"IF1":{"shadow":{"type":"blockLogicTrue","id":"KkiFi.!:PF,jzHmdfMf4"},"block":{"type":"blockButtonIsPressed","id":"X7ICqD9alzb).7@+5k-@","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":")p2RWTVVSR`QL#@o|EdL","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"-jTwyCmC_wZs~y9U.Qu?","fields":{"VALUE":"RIGHT_MINUS"}}}}}},"DO1":{"block":{"type":"blockMotorRun","id":"J8(2P5aNmm[BALbUI~g+","extraState":{"optionLevel":0},"fields":{"METHOD":"MOTOR_RUN_FOREVER"},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"a$}C]al0c@bo6pE@OV9L","fields":{"VAR":{"id":"WfLWxs!;-+H11Ww!!x:_","name":"right","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"unit_angularVelocity","id":"Gyf`7-.ftq9wNMZtMjRe","fields":{"VALUE0":-1000}}}}}},"ELSE":{"block":{"type":"blockMotorStop","id":"HJ29R/djYiWAMl6$lAiU","inputs":{"VAR":{"shadow":{"type":"variables_get_simple_motor_device","id":"aI6NFUD$1k5tfy(Q-V-L","fields":{"VAR":{"id":"WfLWxs!;-+H11Ww!!x:_","name":"right","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"parameters_stop_3","id":"#v4;gZyWP*TJro]{6]%s","fields":{"VALUE":"Stop.COAST"}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}},{"type":"blockGlobalStart","id":"oNK8Crph);pPl`9WLjn{","x":712,"y":915,"next":{"block":{"type":"blockComment","id":"|zg2NR+_I[B*`9}Z/+0G","fields":{"FIELDNAME":"This task will handle the motor that switches the function gearbox."},"next":{"block":{"type":"blockComment","id":",G:DEc1w_F8x;K3M_d_w","fields":{"FIELDNAME":"First it resets the gearbox by finding the start and end stops."},"next":{"block":{"type":"blockMotorRun","id":"t$dM_~8A`j%wi}:d(wdx","extraState":{"optionLevel":3},"fields":{"METHOD":"MOTOR_RUN_UNTIL_STALLED"},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"zr0myoV/UC|3Ox?PhHTI","fields":{"VAR":{"id":"GtM_hctvAF2:Pdx~WV{=","name":"switch","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"unit_angularVelocity","id":"Hc#2x,oNj9gSX(.LWcP4","fields":{"VALUE0":500}}},"LIMIT":{"shadow":{"type":"unit_percent","id":"xSFx/t}6AoN7cCi$.(uH","fields":{"VALUE0":50}}},"THEN":{"shadow":{"type":"parameters_stop_3","id":"!+E^__r9oM}?s|:~br}]","fields":{"VALUE":"Stop.COAST"}}}},"next":{"block":{"type":"blockVariableSetValue","id":"Jp(0X1iCMCe+;0-!]$zY","inputs":{"VAR":{"shadow":{"type":"variables_get_any","id":"Y/EPWY-2AM]]bq=xHe+;","fields":{"VAR":{"id":"K!78++=(@jb1Q@?p`Xo?","name":"right end","type":"Any"}}}},"VALUE0":{"shadow":{"type":"blockMathNumber","id":"SOO%OB9yxJwpUPK8=*ZW","fields":{"NUM":0}},"block":{"type":"blockMotorMeasure","id":"hB:x:x1k$@Tdiio`eX;h","extraState":{"optionLevel":1},"fields":{"METHOD":"MOTOR_ANGLE"},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"X5J{KgIiblrTN:)E?{q1","fields":{"VAR":{"id":"GtM_hctvAF2:Pdx~WV{=","name":"switch","type":"Motor"}}}}}}}},"next":{"block":{"type":"blockMotorRun","id":"iCZ~|_Epo?z5Il(~=AzL","extraState":{"optionLevel":3},"fields":{"METHOD":"MOTOR_RUN_UNTIL_STALLED"},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"s.UUkzq3]lG^T~-eZdOR","fields":{"VAR":{"id":"GtM_hctvAF2:Pdx~WV{=","name":"switch","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"unit_angularVelocity","id":"[5nu6/Mw-3a:vPh?P8jh","fields":{"VALUE0":-500}}},"LIMIT":{"shadow":{"type":"unit_percent","id":"8F5:gU1++[~QQjpx;t}0","fields":{"VALUE0":50}}},"THEN":{"shadow":{"type":"parameters_stop_3","id":"|nfXP%Lx8#;vK]DGRb7j","fields":{"VALUE":"Stop.COAST"}}}},"next":{"block":{"type":"blockVariableSetValue","id":"s]_W*`}3*o[OXUg*-9t3","inputs":{"VAR":{"shadow":{"type":"variables_get_any","id":"vxp2J,QoWz[ZI$4{Fs_N","fields":{"VAR":{"id":"|:C@ETh=EDU-gt}caTMY","name":"left end","type":"Any"}}}},"VALUE0":{"shadow":{"type":"blockMathNumber","id":"SOO%OB9yxJwpUPK8=*ZW","fields":{"NUM":0}},"block":{"type":"blockMotorMeasure","id":"4P[S=$omwW]w8k).!FAO","extraState":{"optionLevel":1},"fields":{"METHOD":"MOTOR_ANGLE"},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"|R6!~jPxY{?X.IM1!4CX","fields":{"VAR":{"id":"GtM_hctvAF2:Pdx~WV{=","name":"switch","type":"Motor"}}}}}}}},"next":{"block":{"type":"blockMotorResetAngle","id":"C.K[AnOtb_Tp/;1bdwK6","inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"y4[%it5ul67jO+H}Ez0H","fields":{"VAR":{"id":"GtM_hctvAF2:Pdx~WV{=","name":"switch","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"unit_angle","id":"N#T([W*,$e7`??QOWFBw","fields":{"VALUE0":0}},"block":{"type":"blockMathFormula","id":"+]dBXOn*_)KCG9u[H`8(","extraState":{"optionLevel":2},"fields":{"FORMULA":"(270 + a - b) / 2"},"inputs":{"a":{"shadow":{"type":"blockMathNumber","id":"XOlE}?1+]HF`B{g4Gk?n","fields":{"NUM":0}},"block":{"type":"blockVariableGetValue","id":"m7ue,%}[Sbv:*/UT$+BJ","inputs":{"VAR":{"shadow":{"type":"variables_get_any","id":"7/6ePKuf;hP;IfCs74@w","fields":{"VAR":{"id":"|:C@ETh=EDU-gt}caTMY","name":"left end","type":"Any"}}}}}}},"b":{"shadow":{"type":"blockMathNumber","id":"^6i|R#:xv21#F{;i.n$X","fields":{"NUM":0}},"block":{"type":"blockVariableGetValue","id":"C}j=SM#7kRSO}FV^qN?Z","inputs":{"VAR":{"shadow":{"type":"variables_get_any","id":"kqqgdu0PR^U0CD6c!-Ls","fields":{"VAR":{"id":"K!78++=(@jb1Q@?p`Xo?","name":"right end","type":"Any"}}}}}}}}}}},"next":{"block":{"type":"blockFunctionCallerStatement","id":"0uv5e#XBt6j9Z7$^;6Sb","extraState":{"optionLevel":1},"fields":{"ICON":"TASK","VAR":{"id":"SfQO0qSRH4KT9-W!daxW"}},"inputs":{"ARG0":{"shadow":{"type":"blockMathNumber","id":"!:R-:.llzJ]rRXVRKQ@C","fields":{"NUM":0}}}},"next":{"block":{"type":"blockLightOnColor","id":"+=zQVtxYxuCj`u}90{T,","extraState":{"optionLevel":1},"fields":{"METHOD":"LIGHT_ON"},"inputs":{"VAR":{"shadow":{"type":"variables_get_color_light_device","id":"E7@[CSx,}},"COLOR":{"shadow":{"type":"variables_get_color","id":"5uh$d0V_,_SsLb-HrR2H","fields":{"COLOUR":"#0000ff","VAR":{"id":"_s-rrV.@96Il~UP_hcog","name":"blue","type":"ColorDef"}}}}},"next":{"block":{"type":"blockComment","id":"~vYo#}-ALMsA6sJuDDOq","fields":{"FIELDNAME":"Now we run the main loop of operating the switch."},"next":{"block":{"type":"blockFlowWhile","id":"NZ4Lr./POLZ{z8HQo*qY","fields":{"MODE":"WHILE"},"inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"+x%C2YgSnI,n|EbGy5_x"}},"DO":{"block":{"type":"blockComment","id":"IUfw=YrE}`{A@5PO57Jj","fields":{"FIELDNAME":"Wait for the center switch to be pressed."},"next":{"block":{"type":"blockWaitUntil","id":"F^iu^]QmQ7OKMJl{;cAH","inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"@XiqFv|*D:/H$+s-#Uv`"},"block":{"type":"blockButtonIsPressed","id":"49Y};Qsb@`y/4V,EBjI8","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":"{!.^$H*ej-we.opIgJ8t","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"14#/*]lgP#K3|)BSOY-y","fields":{"VALUE":"CENTER"}}}}}}},"next":{"block":{"type":"blockComment","id":"FT52M~86uc9v]0NsddtH","fields":{"FIELDNAME":"Then select the function based on which other button is pressed."},"next":{"block":{"type":"blockIfElse","id":".]7+Qn3cxwS/QkIu#-T]","extraState":{"optionLevel":4},"inputs":{"IF0":{"shadow":{"type":"blockLogicTrue","id":"{g9iEDm_bF;zVqny*GW6"},"block":{"type":"blockButtonIsPressed","id":"l=/)4{[uwZH2%A[w/+ZO","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":"mj$NmV]QsZ?oM=t$v_p=","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"~x{]+H`0f,{_J1Q8Ia)W","fields":{"VALUE":"LEFT_PLUS"}}}}}},"DO0":{"block":{"type":"blockComment","id":"sP){gavCsEKiW{qN|B?{","fields":{"FIELDNAME":"Blade up/down function."},"next":{"block":{"type":"blockFunctionCallerStatement","id":":AEVvt#Roy/n499^+QCF","extraState":{"optionLevel":1},"fields":{"ICON":"TASK","VAR":{"id":"SfQO0qSRH4KT9-W!daxW"}},"inputs":{"ARG0":{"shadow":{"type":"blockMathNumber","id":"3(pk!2@:wX0f~9ssS}wd","fields":{"NUM":0}}}},"next":{"block":{"type":"blockLightOnColor","id":"@UXEb0L{Z*n7~CdWb9c!","extraState":{"optionLevel":1},"fields":{"METHOD":"LIGHT_ON"},"inputs":{"VAR":{"shadow":{"type":"variables_get_color_light_device","id":"`jKSWv.Qd)m,5r@8i@BB","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"COLOR":{"shadow":{"type":"variables_get_color","id":":tO#*8%v:8t5;L=F+q1m","fields":{"COLOUR":"#0000ff","VAR":{"id":"_s-rrV.@96Il~UP_hcog","name":"blue","type":"ColorDef"}}}}},"next":{"block":{"type":"blockWaitUntil","id":"y`bBwpNR0=f?DKFU$8e}","inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"K.~|8]y3r)hIvOKB:;pY"},"block":{"type":"blockLogicIsNone","id":"]Rv?K}%b+V#^qjm/1,e8","fields":{"OP":"NOT"},"inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"Njl=W[giy{M)i:$U%yG/"},"block":{"type":"blockButtonIsPressed","id":"vqm-3}mTuo.jj,f!p/XD","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":"f%L9[S8D^`3T7c/^w6KL","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"z-3itP6{W|4u~MVJyBxj","fields":{"VALUE":"LEFT_PLUS"}}}}}}}}}}}}}}}}}},"IF1":{"shadow":{"type":"blockLogicTrue","id":"#~5:*UcEsuTC0D*c%dd6"},"block":{"type":"blockButtonIsPressed","id":"E9xdjAy[J}5R)C@}YX6Z","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":";0%{l?lh7@-WHzhPTC-_","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"FN_DpK|0IxtaIdn,Jg4T","fields":{"VALUE":"RIGHT_MINUS"}}}}}},"DO1":{"block":{"type":"blockComment","id":"1b8qs]0r)/TGEn0L.+KK","fields":{"FIELDNAME":"Ripper function."},"next":{"block":{"type":"blockFunctionCallerStatement","id":"P15n]AnF[dnMA@3fMzoe","extraState":{"optionLevel":1},"fields":{"ICON":"TASK","VAR":{"id":"SfQO0qSRH4KT9-W!daxW"}},"inputs":{"ARG0":{"shadow":{"type":"blockMathNumber","id":"uyBATBdT0}8(Th,o.2:E","fields":{"NUM":1}}}},"next":{"block":{"type":"blockLightOnColor","id":"0zLD0XlfbWFEwBrXu`3K","extraState":{"optionLevel":1},"fields":{"METHOD":"LIGHT_ON"},"inputs":{"VAR":{"shadow":{"type":"variables_get_color_light_device","id":"O6P!+*_s.bz9B5WwRZ@%","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"COLOR":{"shadow":{"type":"variables_get_color","id":"fOpY(_:jT4YHn^qi~+g|","fields":{"COLOUR":"#00ff00","VAR":{"id":"kA|}YYi=|SWR30=Z/tif","name":"green","type":"ColorDef"}}}}},"next":{"block":{"type":"blockWaitUntil","id":"0}!{w[amC@0rWs}C9J_n","inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"K.~|8]y3r)hIvOKB:;pY"},"block":{"type":"blockLogicIsNone","id":"]Ei?RZ~hk/fmi`??2hD]","fields":{"OP":"NOT"},"inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"Njl=W[giy{M)i:$U%yG/"},"block":{"type":"blockButtonIsPressed","id":"lA@4AvyE7Noc/$U|n9t-","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":"0q=fmkO]?r7~Iza[AqD8","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"wy2($|V|8.c.PE,v4Ii=","fields":{"VALUE":"RIGHT_MINUS"}}}}}}}}}}}}}}}}}},"IF2":{"shadow":{"type":"blockLogicTrue","id":":yqK;Ko)F,UB7{UZ=XX/"},"block":{"type":"blockButtonIsPressed","id":"w?,11X_~YWe2r1sEiJ`.","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":"}^8LY1h:6ojvo/I6O~4+","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":".pZbEmK(jCqIp*y@yN9j","fields":{"VALUE":"RIGHT_PLUS"}}}}}},"DO2":{"block":{"type":"blockComment","id":";Ue1jhh-P$}5@;mk`SPG","fields":{"FIELDNAME":"Ladder function."},"next":{"block":{"type":"blockFunctionCallerStatement","id":"wRzY%Lhsc?wyQ6LMBu)L","extraState":{"optionLevel":1},"fields":{"ICON":"TASK","VAR":{"id":"SfQO0qSRH4KT9-W!daxW"}},"inputs":{"ARG0":{"shadow":{"type":"blockMathNumber","id":"@w.y1]!JGpTW=t6HT;aS","fields":{"NUM":2}}}},"next":{"block":{"type":"blockLightOnColor","id":"{WL+M4rfUF:%z#U.$Cgd","extraState":{"optionLevel":1},"fields":{"METHOD":"LIGHT_ON"},"inputs":{"VAR":{"shadow":{"type":"variables_get_color_light_device","id":"0|E75T@P$*@E[7-.f-L/","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"COLOR":{"shadow":{"type":"variables_get_color","id":"az{*n@)^/xirTP{qZ{r*","fields":{"COLOUR":"#ffff00","VAR":{"id":"Xco^(#|Z|18MIT#u{biM","name":"yellow","type":"ColorDef"}}}}},"next":{"block":{"type":"blockWaitUntil","id":"]dFA,`JtRRSfSs^QV8KE","inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"K.~|8]y3r)hIvOKB:;pY"},"block":{"type":"blockLogicIsNone","id":"lt-sXuj_9d:d1BpbkK3I","fields":{"OP":"NOT"},"inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"Njl=W[giy{M)i:$U%yG/"},"block":{"type":"blockButtonIsPressed","id":"$%V)a*!nO$qn(ocBxRyH","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":"7$lZiYB8,]{7|6RpMe.-","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"?IkzlNv;Sh3WwJ67IBfC","fields":{"VALUE":"RIGHT_PLUS"}}}}}}}}}}}}}}}}}},"IF3":{"shadow":{"type":"blockLogicTrue","id":"Vt7[46eTJh(]I*Zy72V["},"block":{"type":"blockButtonIsPressed","id":"_,VGxTEG1e%dtZA]WY;F","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":"x,4h$jIGsCY{s+LY%K~:","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"0!|tw,}p84nn;qnDs!_|","fields":{"VALUE":"LEFT_MINUS"}}}}}},"DO3":{"block":{"type":"blockComment","id":"?4zZ8Q{RL8z84cV{)kAn","fields":{"FIELDNAME":"Blade tilt function."},"next":{"block":{"type":"blockFunctionCallerStatement","id":"=Uo0kPJddoUg+s-@Nz74","extraState":{"optionLevel":1},"fields":{"ICON":"TASK","VAR":{"id":"SfQO0qSRH4KT9-W!daxW"}},"inputs":{"ARG0":{"shadow":{"type":"blockMathNumber","id":"osI4?/]Ar-0EBadn^#@z","fields":{"NUM":3}}}},"next":{"block":{"type":"blockLightOnColor","id":"6wDT%:t`Esh.Ze7qZZN_","extraState":{"optionLevel":1},"fields":{"METHOD":"LIGHT_ON"},"inputs":{"VAR":{"shadow":{"type":"variables_get_color_light_device","id":"KKLiC(MbnG}!p@h^vwA6","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"COLOR":{"shadow":{"type":"variables_get_color","id":"Q5mQB1r8@~p4uc*LDCtH","fields":{"COLOUR":"#ff0000","VAR":{"id":"uO/h@3+4kh@Ac|Z_?Th8","name":"red","type":"ColorDef"}}}}},"next":{"block":{"type":"blockWaitUntil","id":"1r9Nxw:Z|Kcf4JP5T~)(","inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"K.~|8]y3r)hIvOKB:;pY"},"block":{"type":"blockLogicIsNone","id":":j@9aeJycFduVR2b]BP4","fields":{"OP":"NOT"},"inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"Njl=W[giy{M)i:$U%yG/"},"block":{"type":"blockButtonIsPressed","id":"nO+](,p)Z%L=C8E{-DR{","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":"xswaMYpos9^GL{-rP5^Z","fields":{"VAR":{"id":"t6]PeCl+]]mtE7M:R],M","name":"remote","type":"Remote"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"6.Kz(G,);;|[R=S`09(R","fields":{"VALUE":"LEFT_MINUS"}}}}}}}}}}}}}}}}}},"ELSE":{"block":{"type":"blockComment","id":"zRLw8Ih81]cHr+_]%SPN","fields":{"FIELDNAME":"No other button pressed, so don't switch."}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}},{"type":"variables_setup_function","id":"B~q]vZ!#[w@]AJW.r4NV","x":713,"y":-281,"extraState":{"optionLevel":1},"fields":{"ICON":"TASK","VAR":{"id":"SfQO0qSRH4KT9-W!daxW"}},"inputs":{"ARG0":{"shadow":{"type":"variables_setup_function_argument","id":"sfiHHH;M0p:-UCiIiNon","fields":{"VAR":{"id":"f`#%rdf$YNY~-JO!;rhT","name":"number","type":"FunctionArgument"}}}},"STACK":{"block":{"type":"blockComment","id":";56BuFmx;6T6T00aH;B[","fields":{"FIELDNAME":"This function takes care of moving the motor to positions 0, 1, 2, or 3:\n\n0: Blade up/down.\n1: Ripper.\n2: Ladder.\n3: Blade tilt."},"next":{"block":{"type":"blockFlowRepeat","id":"wX[D:H#oO.mT.JrZ)L^K","inputs":{"TIMES":{"shadow":{"type":"blockMathNumber","id":"44!U-](Dj+TB]*XYA5$a","fields":{"NUM":5}}},"DO":{"block":{"type":"blockComment","id":"iXqELwg5~3U-`[(FxUXN","fields":{"FIELDNAME":"Go to the target angle. But give up if it takes more\nthan 2 seconds, which means it's stuck for now."},"next":{"block":{"type":"blockMultiTask","id":"e_/WOVuH`o]gcRA6l03l","extraState":{"optionLevel":0},"fields":{"METHOD":"MULTITASK_RACE"},"inputs":{"TASK0":{"block":{"type":"blockMotorRun","id":"F[dVdZ*Z:*b^62wVCxF:","extraState":{"optionLevel":2},"fields":{"METHOD":"MOTOR_RUN_TO"},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"oY~s0-@1^U95jm}aL6_r","fields":{"VAR":{"id":"GtM_hctvAF2:Pdx~WV{=","name":"switch","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"unit_angularVelocity","id":"oXdA*_j^%Xhm9{X?C(x1","fields":{"VALUE0":750}}},"ANGLE":{"shadow":{"type":"unit_angle","id":"|0r@h9v)Gv^]^bv,OlG`","fields":{"VALUE0":360}},"block":{"type":"blockMathArithmetic","id":"@e!EdrEW@O-W.ZwMf-@3","fields":{"OP":"MULTIPLY"},"inputs":{"A":{"shadow":{"type":"blockMathNumber","id":"33+{-pU0iUFVZl$XCD`k","fields":{"NUM":1}},"block":{"type":"variables_setup_function_argumentConstant","id":"k:b*#0I]A],[@S5I[Q{G","fields":{"VAR":{"text":"number"}}}},"B":{"shadow":{"type":"blockMathNumber","id":"Ygz*BBt8HN{.JU@v7)Rc","fields":{"NUM":90}}}}}},"THEN":{"shadow":{"type":"parameters_stop_4","id":";)04i,KFHFY8yJ{h?6KA","fields":{"VALUE":"Stop.COAST"}}}}}},"TASK1":{"block":{"type":"blockWaitTime","id":".B1e^5,k;^AD8_E19#%T","inputs":{"VALUE0":{"shadow":{"type":"unit_time","id":"kZIKc%HB3dye=1tWNZ`P","fields":{"VALUE0":2000}}}}}}},"next":{"block":{"type":"blockComment","id":"I(EE(O!4(bXo1Hy2_amq","fields":{"FIELDNAME":"Let's check if we're on target."},"next":{"block":{"type":"blockIfElse","id":"hnD5,F8O0fr;IZ/{R3DT","extraState":{"optionLevel":0},"inputs":{"IF0":{"shadow":{"type":"blockLogicTrue","id":"j+9-+KY3m.VxUwWwg0Zf"},"block":{"type":"blockLogicCompare","id":"aJ$DL8L13]_Y%Axy%Lf%","fields":{"OP1":"LTE"},"inputs":{"A":{"shadow":{"type":"blockMathNumber","id":"l(@o!S%R100tDhI4NRHQ","fields":{"NUM":3}},"block":{"type":"blockMathOp","id":"mmRgPr!o7(]`7-?zjOSa","extraState":{"optionLevel":0},"fields":{"OP":"ABS"},"inputs":{"NUM":{"shadow":{"type":"blockMathNumber","id":"`,RjEsgzwC*ySYL||i*#","fields":{"NUM":0}},"block":{"type":"blockMathArithmetic","id":"TBNhoF;H~g.=W+7+l{7p","fields":{"OP":"MINUS"},"inputs":{"A":{"shadow":{"type":"blockMathNumber","id":"fkd~Cu00QFzjWJsXOhRq","fields":{"NUM":1}},"block":{"type":"blockMotorMeasure","id":":^=6g?K5o]U]CmBO%8*[","extraState":{"optionLevel":1},"fields":{"METHOD":"MOTOR_ANGLE"},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"t@hitC^JD314FxmBRb,4","fields":{"VAR":{"id":"GtM_hctvAF2:Pdx~WV{=","name":"switch","type":"Motor"}}}}}}},"B":{"shadow":{"type":"blockMathNumber","id":"p61ZU9G0d,..=]}h[c9Z","fields":{"NUM":1}},"block":{"type":"blockMathArithmetic","id":"DRK^YSi.NmE^+Xpzo2?f","fields":{"OP":"MULTIPLY"},"inputs":{"A":{"shadow":{"type":"blockMathNumber","id":"33+{-pU0iUFVZl$XCD`k","fields":{"NUM":1}},"block":{"type":"variables_setup_function_argumentConstant","id":"dGKYXQ:1MgR:;niDx2@x","fields":{"VAR":{"text":"number"}}}},"B":{"shadow":{"type":"blockMathNumber","id":"f=C)0(tT#sMgu`kV1|]m","fields":{"NUM":90}}}}}}}}}}}},"B":{"shadow":{"type":"blockMathNumber","id":"u^sH;}i[^YyIGW#MymA/","fields":{"NUM":10}}}}}},"DO0":{"block":{"type":"blockComment","id":"jOovlHwhF.2{.|`=r2NX","fields":{"FIELDNAME":"We are close to the target angle.\nso we can exit this repeating loop."},"next":{"block":{"type":"blockFlowBreakContinue","id":"fN*grf18Y-_g/VKOr/N=","fields":{"FLOW":"BREAK"}}}}}},"next":{"block":{"type":"blockComment","id":"sB|uvk-sh_/c~Xlq_?]R","fields":{"FIELDNAME":"Otherwise, we're not done yet, so we must be stuck.\nLet's wiggle the motor around to try to get it unstuck."},"next":{"block":{"type":"blockMotorTrack","id":"~Pu+S*%,~Wz+J|wPx*;z","inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"ST4WrEs#!n:!Ot|tqJBF","fields":{"VAR":{"id":"GtM_hctvAF2:Pdx~WV{=","name":"switch","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"unit_angle","id":"aElZ4G6kN_?^A8h+Ys[$","fields":{"VALUE0":0}}}},"next":{"block":{"type":"blockWaitTime","id":":CR,0g^VJDCSHkYg{XOf","inputs":{"VALUE0":{"shadow":{"type":"unit_time","id":".{cJ7y;X9@HTDt[vZm~)","fields":{"VALUE0":1000}}}},"next":{"block":{"type":"blockMotorTrack","id":"N4dN$yQ.Yo*O1=g))#Qb","inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"DOpfb3bd3IYz@j:*yIR7","fields":{"VAR":{"id":"GtM_hctvAF2:Pdx~WV{=","name":"switch","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"unit_angle","id":"8:?!+z4!|d:YyRzELUot","fields":{"VALUE0":270}}}},"next":{"block":{"type":"blockWaitTime","id":"Y)Va`*IEd;.9m`Op[d?]","inputs":{"VALUE0":{"shadow":{"type":"unit_time","id":"Rk?(p;%eK7h{f5djTWZM","fields":{"VALUE0":1000}}}},"next":{"block":{"type":"blockMotorStop","id":"0n!t9OGkmSnTdJ]!tyg4","inputs":{"VAR":{"shadow":{"type":"variables_get_simple_motor_device","id":"hPg+0E-n5ZXo(LG:D|m,","fields":{"VAR":{"id":"GtM_hctvAF2:Pdx~WV{=","name":"switch","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"parameters_stop_3","id":"pNnc:eu;J4^9g[:]~O4m","fields":{"VALUE":"Stop.COAST"}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}]},"variables":[{"name":"red","id":"uO/h@3+4kh@Ac|Z_?Th8","type":"ColorDef"},{"name":"orange","id":"PbBhi3@n_tXs7EJrgedn","type":"ColorDef"},{"name":"yellow","id":"Xco^(#|Z|18MIT#u{biM","type":"ColorDef"},{"name":"green","id":"kA|}YYi=|SWR30=Z/tif","type":"ColorDef"},{"name":"cyan","id":"FFE|fWaoM:f.dtv#(VU2","type":"ColorDef"},{"name":"blue","id":"_s-rrV.@96Il~UP_hcog","type":"ColorDef"},{"name":"violet","id":"jppN#=b?sft-jQ3aO2~=","type":"ColorDef"},{"name":"magenta","id":"93H`nT:`gVY@Q!(`*c5g","type":"ColorDef"},{"name":"white","id":"XKUh(iy^MLb*+i*5PnYn","type":"ColorDef"},{"name":"none","id":"rz1ZYL.?ep#IDV^cyM!g","type":"ColorDef"},{"name":"remote","id":"t6]PeCl+]]mtE7M:R],M","type":"Remote"},{"name":"switch function","id":"SfQO0qSRH4KT9-W!daxW","type":"Function"},{"name":"left end","id":"|:C@ETh=EDU-gt}caTMY","type":"Any"},{"name":"right end","id":"K!78++=(@jb1Q@?p`Xo?","type":"Any"},{"name":"left","id":"HB$E(E|0GcK=3:b9OGWK","type":"Motor"},{"name":"right","id":"WfLWxs!;-+H11Ww!!x:_","type":"Motor"},{"name":"function","id":"9]^QIL#QX=31WQ@/A7^z","type":"Motor"},{"name":"switch","id":"GtM_hctvAF2:Pdx~WV{=","type":"Motor"},{"name":"number","id":"f`#%rdf$YNY~-JO!;rhT","type":"FunctionArgument"}],"info":{"type":"pybricks","version":"1.2.2"}}
from pybricks.parameters import Button, Color, Direction, Port, Stop
from pybricks.pupdevices import Motor, Remote
from pybricks.tools import multitask, run_task, wait

# Set up all devices.
left = Motor(Port.A, Direction.COUNTERCLOCKWISE)
right = Motor(Port.B, Direction.CLOCKWISE)
function = Motor(Port.C, Direction.CLOCKWISE)
switch = Motor(Port.D, Direction.CLOCKWISE)
remote = Remote(timeout=None)

# Initialize variables.
left_end = 0
right_end = 0

async def switch_function(number):
    await wait(1)
    # This function takes care of moving the motor to positions 0, 1, 2, or 3:

    # 0: Blade up/down.
    # 1: Ripper.
    # 2: Ladder.
    # 3: Blade tilt.
    for count in range(5):
        await wait(1)
        # Go to the target angle. But give up if it takes more
        # than 2 seconds, which means it's stuck for now.
        await multitask(switch.run_target(750, number * 90, Stop.COAST), wait(2000), race=True)
        # Let's check if we're on target.
        if abs(switch.angle() - number * 90) <= 10:
            # We are close to the target angle.
            # so we can exit this repeating loop.
            break
        # Otherwise, we're not done yet, so we must be stuck.
        # Let's wiggle the motor around to try to get it unstuck.
        switch.track_target(0)
        await wait(1000)
        switch.track_target(270)
        await wait(1000)
        switch.stop()

async def main1():
    # This main task will handle driving and the motor
    # that powers (not switches) the function gearbox.
    left.control.limits(acceleration=2500)
    right.control.limits(acceleration=2500)
    while True:
        await wait(1)
        if Button.CENTER in remote.buttons.pressed():
            # If the center button is pressed to change the switch motor,
            # we stop driving and powering the function motor to be safe.
            left.stop()
            right.stop()
            function.stop()
        else:
            # Otherwise drive the motors based on the buttons that are pressed.
            # Use the left/right red buttons for the function motor.
            if Button.LEFT in remote.buttons.pressed():
                function.dc(100)
            elif Button.RIGHT in remote.buttons.pressed():
                function.dc(-100)
            else:
                function.stop()
            # Use the left +/- for the left track.
            if Button.LEFT_PLUS in remote.buttons.pressed():
                left.run(1000)
            elif Button.LEFT_MINUS in remote.buttons.pressed():
                left.run(-1000)
            else:
                left.stop()
            # Use the right +/- for the left track.
            if Button.RIGHT_PLUS in remote.buttons.pressed():
                right.run(1000)
            elif Button.RIGHT_MINUS in remote.buttons.pressed():
                right.run(-1000)
            else:
                right.stop()

async def main2():
    global right_end, left_end
    # This task will handle the motor that switches the function gearbox.
    # First it resets the gearbox by finding the start and end stops.
    await switch.run_until_stalled(500, Stop.COAST, 50)
    right_end = switch.angle()
    await switch.run_until_stalled(-500, Stop.COAST, 50)
    left_end = switch.angle()
    switch.reset_angle((left_end + 270 - right_end) / 2)
    await switch_function(0)
    await remote.light.on(Color.BLUE)
    # Now we run the main loop of operating the switch.
    while True:
        await wait(1)
        # Wait for the center switch to be pressed.
        while not Button.CENTER in remote.buttons.pressed():
            await wait(1)
        # Then select the function based on which other button is pressed.
        if Button.LEFT_PLUS in remote.buttons.pressed():
            # Blade up/down function.
            await switch_function(0)
            await remote.light.on(Color.BLUE)
            while Button.LEFT_PLUS in remote.buttons.pressed():
                await wait(1)
        elif Button.RIGHT_MINUS in remote.buttons.pressed():
            # Ripper function.
            await switch_function(1)
            await remote.light.on(Color.GREEN)
            while Button.RIGHT_MINUS in remote.buttons.pressed():
                await wait(1)
        elif Button.RIGHT_PLUS in remote.buttons.pressed():
            # Ladder function.
            await switch_function(2)
            await remote.light.on(Color.YELLOW)
            while Button.RIGHT_PLUS in remote.buttons.pressed():
                await wait(1)
        elif Button.LEFT_MINUS in remote.buttons.pressed():
            # Blade tilt function.
            await switch_function(3)
            await remote.light.on(Color.RED)
            while Button.LEFT_MINUS in remote.buttons.pressed():
                await wait(1)
        else:
            # No other button pressed, so don't switch.
            pass


async def main():
    await multitask(main1(), main2())

run_task(main())
Python representation of the block program.