2 – Mit Fahrroboter Hindernis erkennen

2

Mit Fahrroboter ein Hindernis erkennen

Das lernst du hier

Programmiere den Roboter so, dass er Hindernissen ausweichen kann, wenn diese von Sensoren erkannt werden.

2a

Einem Hindernis ausweichen

Wie geht das?

Dein Roboter hat in der Grundversion zwei einfache Tastsensoren. Berührt ein solcher Sensor ein Hindernis, dreht der Roboter davon ab und fährt vom Hindernis weg.

Challenge:

> Gehe auf diese Seite: pglu.ch > CODING > ARDUINO ROBOTER
> Verstehe die Animation am Anfang der Seite
Löse die Aufgaben 1-3 und 6 (4+5 kannst du weglassen)
Schaue auch die Lernvideos

2b

Mit LED blinken, wenn Hindernis berührt wird

Wie geht das?

In Challenge 2a hast du gelernt, dass der Block PAUSIERE nicht die Fahrt des Roboters pausiert, sondern den Ablauf des Programms. So gesehen, ist dein Arduino während dieser Pause untätig. Nutze die Zeit dieser Programmpausen und lasse eine LED blinken!

Challenge:

> Gehe auf diese Seite: pglu.ch > CODING > ARDUINO ROBOTER
Löse die Aufgaben 4
Schaue auch die Lernvideos

Hinweis: Vereinfache das Blinken der LED in Lösung 4 mit: ABLAUF > WIEDERHOLE 5 x MAL

2c

Eigene Fahrfunktionen dank Unterprogrammen

Wie geht das?

Unterprogramme (Funktionen) sind Programmschnipsel, welche du einmal schreibst und gleich mehrfach verwenden kannst. Dadurch wird dein Sketch übersichtlicher und du sparst erst noch Zeit.

Nutze diese Vereinfachung, um eigene Fahrfunktionen für den Roboter zu entwickeln: Nach einer Berührung durch den Sensor soll der Roboter zuerst kurz rückwärtsfahren, bevor er dann vom Hindernis wegdreht.

Challenge:

Challenge: XML-Code in Editor einfügen
<xml xmlns="https://developers.google.com/blockly/xml"><block type="basic_comment" id="/11t(ikP@^J4;Y^tMv}(" x="1052" y="-164"><field name="COMMENT">FAHRROBOTER Challenge 2c "Funktionen"&amp;#10;&amp;#10;Setze die Blöcke in den Hauptloop ein. Wenn du mehr Blöcke brauchst, findest du sie im Menu</field></block><block type="basic_comment" id="=,6n}hc=k0J:e{nYCIF:" x="283" y="-10"><field name="COMMENT">Fülle diese Funktionsklammern mit den&amp;#10;richtigen Motorenblöcken.&amp;#10;Beachte, dass einzelne Funktionen zeitlich&amp;#10;begrenzt sein müssen und daher noch eine &amp;#10;Pause eingesetzt werden muss.&amp;#10;&amp;#10;Um dies zu verstehen, reicht es, wenn du die&amp;#10;Lösung aus Challenge 2a weiterentwickelst!</field></block><block type="procedures_defnoreturn" id="`r(nNtAGp/NhtP.8WoZr" x="621" y="-11"><field name="NAME">fahre vorwärts bis etwas geschieht</field></block><block type="basic_main_loop" id="8Np#B)0Vf^SF*=TW~5k/" deletable="false" x="1051" y="-16"><value name="BLINK"><block type="basic_blinkcode" id="W.$!O{rF:YlxA}+Dr!t+"><field name="SHORT">1</field><field name="LONG">1</field></block></value><statement name="CODE"><block type="logic_if" id="ib*(rqaYr@%E:#xei8T9"><mutation xmlns="http://www.w3.org/1999/xhtml" else="1"></mutation><value name="IF0"><block type="sensor_test_state" id="(^?h*B.{Bs-TKI]O1b(8"><field name="MODE">STANDARD</field><value name="SENSOR"><block type="sensor_pin" id="~a5QJt_7mK_wC%lx1$|)"><field name="SENSOR">SENSOR1</field></block></value><value name="STATE"><block type="basic_digital_state" id="N9k%|v._jD9]=vdiPW!C"><field name="STATE">LOW</field></block></value></block></value><statement name="DO0"><block type="procedures_callnoreturn" id="col]N1EAudjvR#i6{G=A"><mutation name="fahre rückwärts 500ms"></mutation><next><block type="procedures_callnoreturn" id="j@qOhm]=3zMlQ[cGrKuj"><mutation name="drehe rechts 500ms"></mutation></block></next></block></statement><statement name="ELSE"><block type="procedures_callnoreturn" id="248kT~^?2AU6zeDyKC[X"><mutation name="fahre vorwärts bis etwas geschieht"></mutation></block></statement><next><block type="logic_if" id="f8DBb0IIYDeSz;#qM9q/"><mutation xmlns="http://www.w3.org/1999/xhtml" else="1"></mutation><value name="IF0"><block type="sensor_test_state" id="=t}3H}Sbr)6L,BK(hL7("><field name="MODE">STANDARD</field><value name="SENSOR"><block type="sensor_pin" id=".G_L6ZFSm0(CTK8XXcbD"><field name="SENSOR">SENSOR2</field></block></value><value name="STATE"><block type="basic_digital_state" id="UCK81n`S2!,}:(xJ^a%1"><field name="STATE">LOW</field></block></value></block></value><statement name="DO0"><block type="procedures_callnoreturn" id="a4)ZX|USw72?@l3.}Vpt"><mutation name="fahre rückwärts 500ms"></mutation><next><block type="procedures_callnoreturn" id="Z3AF[68Rb.HPFV$8UMJQ"><mutation name="drehe links 500ms"></mutation></block></next></block></statement><statement name="ELSE"><block type="procedures_callnoreturn" id="{d)2c)Gx78aLbK=7[Ocu"><mutation name="fahre vorwärts bis etwas geschieht"></mutation></block></statement></block></next></block></statement></block><block type="procedures_defnoreturn" id="C,YrZ*yxn#BOfVGg9k]U" x="623" y="153"><field name="NAME">fahre rückwärts 500ms</field></block><block type="procedures_defnoreturn" id="rnw$}:bIu)#|S~`W2bf9" x="628" y="318"><field name="NAME">drehe links 500ms</field></block><block type="procedures_defnoreturn" id="r0p4q^wSn8jFoh|xcvyo" x="626" y="474"><field name="NAME">drehe rechts 500ms</field></block></xml>

Mögliche Lösung:

Lösung: XML-Code in Editor einfügen
<xml xmlns="https://developers.google.com/blockly/xml"><block type="basic_comment" id="/11t(ikP@^J4;Y^tMv}(" x="1052" y="-164"><field name="COMMENT">FAHRROBOTER Challenge 2c "Funktionen"&amp;#10;&amp;#10;Setze die Blöcke in den Hauptloop ein. Wenn du mehr Blöcke brauchst, findest du sie im Menu</field></block><block type="basic_comment" id="=,6n}hc=k0J:e{nYCIF:" x="299" y="-8"><field name="COMMENT">Entwickle weitere Fahrfunktionen, wie:&amp;#10;&amp;#10;&gt; das Fahren einer sanften Kurve&amp;#10;&gt; das Beschelunigen oder Bremsen&amp;#10;&gt; ...</field></block><block type="procedures_defnoreturn" id="`r(nNtAGp/NhtP.8WoZr" x="630" y="-9"><field name="NAME">fahre vorwärts bis etwas geschieht</field><statement name="STACK"><block type="motor_write_percentage" id=")^qAP$1H{ao6|]L.+y80"><value name="MOTOR"><block type="motor_pin" id="[7[,WvWOT/tBl2wGew$f"><field name="MOTOR">MOTOR1</field></block></value><value name="PERCENTAGE"><block type="math_number" id="X27p;J^:xR/wgXQXF_1j"><field name="NUM">100</field></block></value><next><block type="motor_write_percentage" id="|!Ki}]8a(87UTyV8@;bv"><value name="MOTOR"><block type="motor_pin" id="xfSSm~WJzhQ76fD^Sil0"><field name="MOTOR">MOTOR2</field></block></value><value name="PERCENTAGE"><block type="math_number" id="2hwSJ8^l%z6qH%)}#9=x"><field name="NUM">100</field></block></value></block></next></block></statement></block><block type="basic_main_loop" id="8Np#B)0Vf^SF*=TW~5k/" deletable="false" x="1051" y="-16"><value name="BLINK"><block type="basic_blinkcode" id="W.$!O{rF:YlxA}+Dr!t+"><field name="SHORT">1</field><field name="LONG">1</field></block></value><statement name="CODE"><block type="logic_if" id="ib*(rqaYr@%E:#xei8T9"><mutation xmlns="http://www.w3.org/1999/xhtml" else="1"></mutation><value name="IF0"><block type="sensor_test_state" id="(^?h*B.{Bs-TKI]O1b(8"><field name="MODE">STANDARD</field><value name="SENSOR"><block type="sensor_pin" id="~a5QJt_7mK_wC%lx1$|)"><field name="SENSOR">SENSOR1</field></block></value><value name="STATE"><block type="basic_digital_state" id="N9k%|v._jD9]=vdiPW!C"><field name="STATE">LOW</field></block></value></block></value><statement name="DO0"><block type="procedures_callnoreturn" id="col]N1EAudjvR#i6{G=A"><mutation name="fahre rückwärts 500ms"></mutation><next><block type="procedures_callnoreturn" id="j@qOhm]=3zMlQ[cGrKuj"><mutation name="drehe rechts 500ms"></mutation></block></next></block></statement><statement name="ELSE"><block type="procedures_callnoreturn" id="248kT~^?2AU6zeDyKC[X"><mutation name="fahre vorwärts bis etwas geschieht"></mutation></block></statement><next><block type="logic_if" id="f8DBb0IIYDeSz;#qM9q/"><mutation xmlns="http://www.w3.org/1999/xhtml" else="1"></mutation><value name="IF0"><block type="sensor_test_state" id="=t}3H}Sbr)6L,BK(hL7("><field name="MODE">STANDARD</field><value name="SENSOR"><block type="sensor_pin" id=".G_L6ZFSm0(CTK8XXcbD"><field name="SENSOR">SENSOR2</field></block></value><value name="STATE"><block type="basic_digital_state" id="UCK81n`S2!,}:(xJ^a%1"><field name="STATE">LOW</field></block></value></block></value><statement name="DO0"><block type="procedures_callnoreturn" id="a4)ZX|USw72?@l3.}Vpt"><mutation name="fahre rückwärts 500ms"></mutation><next><block type="procedures_callnoreturn" id="Z3AF[68Rb.HPFV$8UMJQ"><mutation name="drehe links 500ms"></mutation></block></next></block></statement><statement name="ELSE"><block type="procedures_callnoreturn" id="{d)2c)Gx78aLbK=7[Ocu"><mutation name="fahre vorwärts bis etwas geschieht"></mutation></block></statement></block></next></block></statement></block><block type="procedures_defnoreturn" id="C,YrZ*yxn#BOfVGg9k]U" x="628" y="151"><field name="NAME">fahre rückwärts 500ms</field><statement name="STACK"><block type="motor_write_percentage" id="3B^Sh_ZJo{$uA{KiqzHD"><value name="MOTOR"><block type="motor_pin" id="!^=y~tz)e8xoVyU@UdJf"><field name="MOTOR">MOTOR1</field></block></value><value name="PERCENTAGE"><block type="math_number" id="B#I]nH;!a$Pve9mhGS#P"><field name="NUM">-100</field></block></value><next><block type="motor_write_percentage" id="DjPDRkCjo}t2P?BJ.0?!"><value name="MOTOR"><block type="motor_pin" id="kdt1AEL%An`G0Mi2g[kD"><field name="MOTOR">MOTOR2</field></block></value><value name="PERCENTAGE"><block type="math_number" id="bBr8K`n}5L:t8#F3#1$l"><field name="NUM">-100</field></block></value><next><block type="flow_delay" id="AZ$eK$v{_J2#oM4[V`Ts"><value name="DELAY"><block type="math_number" id="[jfzc)A%v348VV6?u||C"><field name="NUM">500</field></block></value></block></next></block></next></block></statement></block><block type="procedures_defnoreturn" id="rnw$}:bIu)#|S~`W2bf9" x="628" y="356"><field name="NAME">drehe links 500ms</field><statement name="STACK"><block type="motor_write_percentage" id="jp@tr7L#,WcRy:.hCKX`"><value name="MOTOR"><block type="motor_pin" id="gDrD;zg2bp(,|lSN3_?9"><field name="MOTOR">MOTOR1</field></block></value><value name="PERCENTAGE"><block type="math_number" id="yr~G{SY`Kk$}[)YYzg.h"><field name="NUM">-100</field></block></value><next><block type="motor_write_percentage" id="]s:;^*EiO1QRPv/12$$w"><value name="MOTOR"><block type="motor_pin" id="e24uxHVgwiv,VjDF,($P"><field name="MOTOR">MOTOR2</field></block></value><value name="PERCENTAGE"><block type="math_number" id="%k|GKy~^ajCbeE[/)YnY"><field name="NUM">100</field></block></value><next><block type="flow_delay" id="e+ERj-iG%M6Zjo!FK,C/"><value name="DELAY"><block type="math_number" id="qCO7Z|UID2pam6?UT7|S"><field name="NUM">500</field></block></value></block></next></block></next></block></statement></block><block type="procedures_defnoreturn" id="r0p4q^wSn8jFoh|xcvyo" x="626" y="564"><field name="NAME">drehe rechts 500ms</field><statement name="STACK"><block type="motor_write_percentage" id="a}K`$.4%kg%Zxz)sDB$}"><value name="MOTOR"><block type="motor_pin" id="%7dj(gg10iq2+A%}uR(n"><field name="MOTOR">MOTOR1</field></block></value><value name="PERCENTAGE"><block type="math_number" id="pgvt:Ku%TPNUp8VeJRjs"><field name="NUM">100</field></block></value><next><block type="motor_write_percentage" id="7E%CtE6[:f1[rr!l.Yb1"><value name="MOTOR"><block type="motor_pin" id="Y%m6EGwA!(42RseX:~pv"><field name="MOTOR">MOTOR2</field></block></value><value name="PERCENTAGE"><block type="math_number" id="PWd9d6yS,6q;iV%iW^E5"><field name="NUM">-100</field></block></value><next><block type="flow_delay" id="%v`nwTgMrV/|W`?YZ~0|"><value name="DELAY"><block type="math_number" id="At[A(L,Zfk2+`wB}aI`U"><field name="NUM">500</field></block></value></block></next></block></next></block></statement></block></xml>

Erfahre hier mehr über Unterprogramme: workshop.pglu.ch > Sketch > Funktion

2d

Mit Pixeln blinken, wenn Hindernis berührt wird

Wie geht das?

In Challenge 2b hast du LEDs blinken lassen, wenn dein Roboter auf ein Hindernis gestossen ist.

Schliesse anstelle der LEDs einen Neopixel-Stripe oder eine Matrix (Bild) an den Roboter an und programmiere deine eigenen Lichteffekte!

> Verstehe, wie Pixel funktionieren: pglu.ch > CODING > NEOPIXEL
> Setze anstelle der Pause das Lauflicht aus MATRIX > Aufgabe 2 ein
> Erfahre mehr über Lauflichter: workshop.pglu.ch > SKETCH > zähle-von-bis

Challenge:

Challenge: XML-Code in Editor einfügen
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="$?@G1IQZ5n8rPS$T16dY">Pixel</variable></variables><block type="basic_comment" id="`fup2r.y#_[m)mK@Pli]" x="256" y="-159"><field name="COMMENT">Arduino Roboter mit Neopixel-Blinker&amp;#10;Mehr Infos zu Lauflichtern: https://workshop.pglu.ch/arduino-programmieren/zaehle-von-bis/</field></block><block type="set_neo_pixel" id="MP$X*yBL::d|L9jK9G49" x="258" y="-72"><value name="NUM_LEDS"><block type="math_number" id="wvsvwEqn$5L,nE:k$8N~"><field name="NUM">16</field></block></value><value name="BRIGHTNESS"><block type="math_number" id="VuHjy7;~03TP:nh(v$wP"><field name="NUM">50</field></block></value><value name="OUTTURN"><block type="led_pin" id=".8=ktG$NGAxiuyagYp_4"><field name="LED">LED1</field></block></value></block><block type="basic_main_loop" id="pYslg;/rwu7z6@wd=Lbh" deletable="false" x="258" y="32"><value name="BLINK"><block type="basic_blinkcode" id="Y:W=wbeVanXqOuR!q3W@"><field name="SHORT">1</field><field name="LONG">1</field></block></value><statement name="CODE"><block type="procedures_callnoreturn" id="s~ZpHk_eat|^S={E}AJw"><mutation name="vor mit Pixel grün"></mutation><next><block type="logic_if" id="4wE*o{q.ZZ;uMiS;Pc{U"><value name="IF0"><block type="sensor_test_state" id="]!gFzY,ae(2?|gE#t.CU"><field name="MODE">STANDARD</field><value name="SENSOR"><block type="sensor_pin" id="acTsja8e#9dqc]0|Ea8+"><field name="SENSOR">SENSOR1</field></block></value><value name="STATE"><block type="basic_digital_state" id="6Nj32(qr+d.Ud5fZjJTt"><field name="STATE">LOW</field></block></value></block></value><statement name="DO0"><block type="procedures_callnoreturn" id="4]b5T0*m_b~~#VGqxu)+"><mutation name="rueck500 mit Pixel Weiss"></mutation><next><block type="procedures_callnoreturn" id="`l@S!lx^]/ia|yP0~avF"><mutation name="links500 mit Pixellauflicht orange"></mutation></block></next></block></statement><next><block type="logic_if" id="DZ#g-WCtaqk~]df#@JMy"><value name="IF0"><block type="sensor_test_state" id="?{|QOe9wnq~stzx9o3d,"><field name="MODE">STANDARD</field><value name="SENSOR"><block type="sensor_pin" id="RHwY{p9jJTr;aYfE:ilA"><field name="SENSOR">SENSOR2</field></block></value><value name="STATE"><block type="basic_digital_state" id=";zftsfzzukOF;?[nvt:C"><field name="STATE">LOW</field></block></value></block></value><statement name="DO0"><block type="procedures_callnoreturn" id="IiQfXT}dZINn0LlB@%i,"><mutation name="rueck500 mit Pixel Weiss"></mutation><next><block type="procedures_callnoreturn" id="#=W.b[XHjG:`^yel^~Mz"><mutation name="rechts500 mit Pixellauflicht orange"></mutation></block></next></block></statement></block></next></block></next></block></statement></block><block type="basic_comment" id="=LO+E%@!TG;.pF4]hEA7" x="787" y="49"><field name="COMMENT">Die Funkion "vor" wird ausgeführt</field></block><block type="procedures_defnoreturn" id="wc?I_=b[UaqbCMo(d#:F" x="1244" y="45"><field name="NAME">vor mit Pixel grün</field><statement name="STACK"><block type="motor_write_percentage" id="@/31FAbTyQumb0j,H?;j"><value name="MOTOR"><block type="motor_pin" id="_JmE)uqboG1L+!7TdxjL"><field name="MOTOR">MOTOR1</field></block></value><value name="PERCENTAGE"><block type="math_number" id="v6^%;fpTcJS24S@P*l5]"><field name="NUM">80</field></block></value><next><block type="motor_write_percentage" id="fTK!6D^z@yqbktY1O;+3"><value name="MOTOR"><block type="motor_pin" id="iz!W(f5_B3t,ZR,;X}c;"><field name="MOTOR">MOTOR2</field></block></value><value name="PERCENTAGE"><block type="math_number" id="+IO!4T)T5A?r32KySvW!"><field name="NUM">80</field></block></value></block></next></block></statement></block><block type="basic_comment" id="[bUK6uJ:u:i3@Ja-EDSh" x="788" y="91"><field name="COMMENT">Wird S1 berührt kommt die Funktion...</field></block><block type="basic_comment" id=",~#sm~@T_PT@P{CnXr|2" x="791" y="136"><field name="COMMENT">...rueck500 und dann...</field></block><block type="basic_comment" id="DJ}Q?A{8n?QSCIw:mZ3q" x="788" y="184"><field name="COMMENT">...links500 zum Einsatz</field></block><block type="procedures_defnoreturn" id="!~O3Z@ml~lm7V[RbKOy6" x="1247" y="251"><field name="NAME">rueck500 mit Pixel Weiss</field><statement name="STACK"><block type="motor_write_percentage" id="W]23SNy.3ba8hPM)Y#20"><value name="MOTOR"><block type="motor_pin" id=",km+FnQe7/e#nyYX}}uq"><field name="MOTOR">MOTOR1</field></block></value><value name="PERCENTAGE"><block type="math_number" id="NLS^=rexTIRnE?66y)?v"><field name="NUM">-100</field></block></value><next><block type="motor_write_percentage" id="z]X_2nxS#]y1TVe`RoaT"><value name="MOTOR"><block type="motor_pin" id="8_v/]7%A@1]^=LI/g_j["><field name="MOTOR">MOTOR2</field></block></value><value name="PERCENTAGE"><block type="math_number" id="-u~P8wt^1DEMD;;u5Pmb"><field name="NUM">-100</field></block></value><next><block type="flow_delay" id="3U:W^vI~=zMn5|@l;J01"><value name="DELAY"><block type="math_number" id="mo-@wImU1_pF*yb!Hlc="><field name="NUM">500</field></block></value></block></next></block></next></block></statement></block><block type="basic_comment" id="PwEXFnp9rf.50^}0v@Zi" x="263" y="389"><field name="COMMENT">Füge diese Neopixel Schnipsel an den richtigen Stellen in die Fahrfunktionen ein.&amp;#10;&amp;#10;Spiele mit den  Pausenzeiten, Farben und der Anzahl Pixel!</field></block><block type="basic_comment" id=";[ab`]COLD6|1Uq7`we6" x="265" y="479"><field name="COMMENT">Lauflicht orange</field></block><block type="flow_for" id="G17i{TFU}l#4|y$xN_t#" x="264" y="536"><field name="VAR" id="$?@G1IQZ5n8rPS$T16dY">Pixel</field><value name="FROM"><block type="math_number" id="p/t^x7caYxi^MJXgs@?Q"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number" id="ep%[_C82k=pH{Rg5aP0L"><field name="NUM">16</field></block></value><value name="BY"><block type="math_number" id="Uv5BkvOy@RBO_%8~%DdE"><field name="NUM">1</field></block></value><statement name="DO"><block type="set_pixel_color" id="]]@^`J_Fw60v;HUzfV=U"><field name="MODE">MODE1</field><value name="FROM"><block type="variables_get" id="#7IG:6=n+_.BzB6wCb#,"><field name="VAR" id="$?@G1IQZ5n8rPS$T16dY">Pixel</field></block></value><value name="TO"><block type="math_number" id="2{Cj:7A=K:|QP4!;F$pZ"><field name="NUM">1</field></block></value><value name="H"><block type="math_number" id="SflO:UBGF)2cJ*pP8`Q*"><field name="NUM">20</field></block></value><value name="S"><block type="math_number" id=".-q?S2xZNq(H-H*@|N(2"><field name="NUM">100</field></block></value><value name="B"><block type="math_number" id="p.u+#;DKPyySbI0d!9a%"><field name="NUM">100</field></block></value><next><block type="flow_delay" id="o[G;wsJ|KpmH?k5zMTAI"><value name="DELAY"><block type="math_number" id="OQu^YP{/O04N(yE4ZEtR"><field name="NUM">33</field></block></value></block></next></block></statement></block><block type="procedures_defnoreturn" id="n6XT0eQ|^EgjUXtmm@;c" x="1246" y="510"><field name="NAME">links500 mit Pixellauflicht orange</field><statement name="STACK"><block type="motor_write_percentage" id="L]fgJ/C}8#B!oV[8|o+?"><value name="MOTOR"><block type="motor_pin" id="@*;@{{3yVo*0J[VwK)u#"><field name="MOTOR">MOTOR1</field></block></value><value name="PERCENTAGE"><block type="math_number" id="2#MLNz.mO[EzMQVWRG4."><field name="NUM">60</field></block></value><next><block type="motor_write_percentage" id="0cmykxCjrzIv}Prnxm]E"><value name="MOTOR"><block type="motor_pin" id="g.CREhghO,#/`=o[/dpI"><field name="MOTOR">MOTOR2</field></block></value><value name="PERCENTAGE"><block type="math_number" id="gQL?|C)bPTC{-AA1Wre_"><field name="NUM">-60</field></block></value></block></next></block></statement></block><block type="basic_comment" id="k.*%TrTXl*X_umdcY]64" x="-34" y="724"><field name="COMMENT">chomsch druus, wieso 1 &gt; 16 und 16 &gt; 1 ?</field></block><block type="flow_for" id="$[X,|*v@*!FE~g^2Fi#V" x="262" y="723"><field name="VAR" id="$?@G1IQZ5n8rPS$T16dY">Pixel</field><value name="FROM"><block type="math_number" id="/1~?-m(F5f{sg_y3(FfH"><field name="NUM">16</field></block></value><value name="TO"><block type="math_number" id="|OnB()kZ^wI-Z%?bx}ko"><field name="NUM">1</field></block></value><value name="BY"><block type="math_number" id="B?ta.Ff/r#a[dgmgy^kt"><field name="NUM">1</field></block></value><statement name="DO"><block type="set_pixel_color" id="H1~~`1ooEX5*Z)V_RMHN"><field name="MODE">MODE1</field><value name="FROM"><block type="variables_get" id="i$kmxSTmISSm8NJP}Col"><field name="VAR" id="$?@G1IQZ5n8rPS$T16dY">Pixel</field></block></value><value name="TO"><block type="math_number" id="Eh!vv,7ZHe#F/$o:V;%n"><field name="NUM">1</field></block></value><value name="H"><block type="math_number" id="WupFr1Fdv/a*dGDRJk_o"><field name="NUM">20</field></block></value><value name="S"><block type="math_number" id="L8coG:OImL}6=Pvj[gU$"><field name="NUM">100</field></block></value><value name="B"><block type="math_number" id="Uy*57Fk*[C`sr=t6%8QZ"><field name="NUM">100</field></block></value><next><block type="flow_delay" id="qUs=:anQrX^V,FJz{NO("><value name="DELAY"><block type="math_number" id=";^,!H2Zqf4T#hhHR*3)9"><field name="NUM">33</field></block></value></block></next></block></statement></block><block type="procedures_defnoreturn" id="=%q9Bj*vb@hrq(4|mdMu" x="1247" y="723"><field name="NAME">rechts500 mit Pixellauflicht orange</field><statement name="STACK"><block type="motor_write_percentage" id="vEE2=!D,#uW]sV^gxhud"><value name="MOTOR"><block type="motor_pin" id="1ynquHyGZij_Pe1`zX}L"><field name="MOTOR">MOTOR1</field></block></value><value name="PERCENTAGE"><block type="math_number" id="X]|ShOGCpF#)rzSS!p!Q"><field name="NUM">-60</field></block></value><next><block type="motor_write_percentage" id="b]5|R*d1f8uT||-{C(`C"><value name="MOTOR"><block type="motor_pin" id="9:n*VpUAP9FW|4Kz`9.-"><field name="MOTOR">MOTOR2</field></block></value><value name="PERCENTAGE"><block type="math_number" id="^/J%^-*^aIDFOy-yxuHT"><field name="NUM">60</field></block></value></block></next></block></statement></block><block type="basic_comment" id="t@,a,8O|SOBo1gWT8qD+" x="260" y="923"><field name="COMMENT">leuchte weiss</field></block><block type="set_pixel_color" id="op4]zXqQ740Wy=-Tf5Re" x="259" y="978"><field name="MODE">MODE1</field><value name="FROM"><block type="math_number" id="=+l%)=5nah;BgnAcFp}_"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number" id="`W0FB_$5kj$%cdcr5a!."><field name="NUM">16</field></block></value><value name="H"><block type="math_number" id="g$Q-I@s{`37V)S5I3Cn-"><field name="NUM">0</field></block></value><value name="S"><block type="math_number" id="gCr^hUl|=J)xGG^x3mZ*"><field name="NUM">0</field></block></value><value name="B"><block type="math_number" id="9#(;Rvi.R2^li^zXy/Ja"><field name="NUM">100</field></block></value></block><block type="basic_comment" id="Hmng;OxB6LEyk8z@@{+V" x="260" y="1082"><field name="COMMENT">leuchte grün</field></block><block type="set_pixel_color" id="WU7h#@3K^{_OEbnWR+Hq" x="259" y="1143"><field name="MODE">MODE1</field><value name="FROM"><block type="math_number" id="gvc,$9A)lQ0w4iM~]jsb"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number" id="LDnoX{@2(nT2%|`]o5?r"><field name="NUM">16</field></block></value><value name="H"><block type="math_number" id="vm/-7}+V=;qas{(8yg2U"><field name="NUM">120</field></block></value><value name="S"><block type="math_number" id="U?Wa^|@XL(.f~Rsd?c5L"><field name="NUM">100</field></block></value><value name="B"><block type="math_number" id="Nu`29JdjnH3cpMuq?^cG"><field name="NUM">100</field></block></value></block></xml>

Mögliche Lösung:

Lösung: XML-Code in Editor einfügen
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="$?@G1IQZ5n8rPS$T16dY">Pixel</variable></variables><block type="basic_comment" id="`fup2r.y#_[m)mK@Pli]" x="256" y="-159"><field name="COMMENT">Arduino Roboter mit Neopixel-Blinker&amp;#10;Mehr Infos zu Lauflichtern: https://workshop.pglu.ch/arduino-programmieren/zaehle-von-bis/</field></block><block type="set_neo_pixel" id="MP$X*yBL::d|L9jK9G49" x="258" y="-72"><value name="NUM_LEDS"><block type="math_number" id="wvsvwEqn$5L,nE:k$8N~"><field name="NUM">16</field></block></value><value name="BRIGHTNESS"><block type="math_number" id="VuHjy7;~03TP:nh(v$wP"><field name="NUM">50</field></block></value><value name="OUTTURN"><block type="led_pin" id="N(iSG[7Z)Q%C!Sdv[+0?"><field name="LED">LED1</field></block></value></block><block type="basic_main_loop" id="pYslg;/rwu7z6@wd=Lbh" deletable="false" x="258" y="32"><value name="BLINK"><block type="basic_blinkcode" id="Y:W=wbeVanXqOuR!q3W@"><field name="SHORT">1</field><field name="LONG">1</field></block></value><statement name="CODE"><block type="procedures_callnoreturn" id="s~ZpHk_eat|^S={E}AJw"><mutation name="vor mit Pixel grün"></mutation><next><block type="logic_if" id="4wE*o{q.ZZ;uMiS;Pc{U"><value name="IF0"><block type="sensor_test_state" id="]!gFzY,ae(2?|gE#t.CU"><field name="MODE">STANDARD</field><value name="SENSOR"><block type="sensor_pin" id="acTsja8e#9dqc]0|Ea8+"><field name="SENSOR">SENSOR1</field></block></value><value name="STATE"><block type="basic_digital_state" id="6Nj32(qr+d.Ud5fZjJTt"><field name="STATE">LOW</field></block></value></block></value><statement name="DO0"><block type="procedures_callnoreturn" id="4]b5T0*m_b~~#VGqxu)+"><mutation name="rueck500 mit Pixel Weiss"></mutation><next><block type="procedures_callnoreturn" id="`l@S!lx^]/ia|yP0~avF"><mutation name="links500 mit Pixellauflicht orange"></mutation></block></next></block></statement><next><block type="logic_if" id="DZ#g-WCtaqk~]df#@JMy"><value name="IF0"><block type="sensor_test_state" id="?{|QOe9wnq~stzx9o3d,"><field name="MODE">STANDARD</field><value name="SENSOR"><block type="sensor_pin" id="RHwY{p9jJTr;aYfE:ilA"><field name="SENSOR">SENSOR2</field></block></value><value name="STATE"><block type="basic_digital_state" id=";zftsfzzukOF;?[nvt:C"><field name="STATE">LOW</field></block></value></block></value><statement name="DO0"><block type="procedures_callnoreturn" id="IiQfXT}dZINn0LlB@%i,"><mutation name="rueck500 mit Pixel Weiss"></mutation><next><block type="procedures_callnoreturn" id="#=W.b[XHjG:`^yel^~Mz"><mutation name="rechts500 mit Pixellauflicht orange"></mutation></block></next></block></statement></block></next></block></next></block></statement></block><block type="basic_comment" id="=LO+E%@!TG;.pF4]hEA7" x="787" y="49"><field name="COMMENT">Die Funkion "vor" wird ausgeführt</field></block><block type="procedures_defnoreturn" id="wc?I_=b[UaqbCMo(d#:F" x="1244" y="45"><field name="NAME">vor mit Pixel grün</field><statement name="STACK"><block type="motor_write_percentage" id="@/31FAbTyQumb0j,H?;j"><value name="MOTOR"><block type="motor_pin" id="_JmE)uqboG1L+!7TdxjL"><field name="MOTOR">MOTOR1</field></block></value><value name="PERCENTAGE"><block type="math_number" id="v6^%;fpTcJS24S@P*l5]"><field name="NUM">80</field></block></value><next><block type="motor_write_percentage" id="fTK!6D^z@yqbktY1O;+3"><value name="MOTOR"><block type="motor_pin" id="iz!W(f5_B3t,ZR,;X}c;"><field name="MOTOR">MOTOR2</field></block></value><value name="PERCENTAGE"><block type="math_number" id="+IO!4T)T5A?r32KySvW!"><field name="NUM">80</field></block></value><next><block type="set_pixel_color" id="WU7h#@3K^{_OEbnWR+Hq"><field name="MODE">MODE1</field><value name="FROM"><block type="math_number" id="gvc,$9A)lQ0w4iM~]jsb"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number" id="LDnoX{@2(nT2%|`]o5?r"><field name="NUM">16</field></block></value><value name="H"><block type="math_number" id="vm/-7}+V=;qas{(8yg2U"><field name="NUM">120</field></block></value><value name="S"><block type="math_number" id="U?Wa^|@XL(.f~Rsd?c5L"><field name="NUM">100</field></block></value><value name="B"><block type="math_number" id="Nu`29JdjnH3cpMuq?^cG"><field name="NUM">100</field></block></value></block></next></block></next></block></statement></block><block type="basic_comment" id="[bUK6uJ:u:i3@Ja-EDSh" x="788" y="91"><field name="COMMENT">Wird S1 berührt kommt die Funktion...</field></block><block type="basic_comment" id=",~#sm~@T_PT@P{CnXr|2" x="791" y="136"><field name="COMMENT">...rueck500 und dann...</field></block><block type="basic_comment" id="DJ}Q?A{8n?QSCIw:mZ3q" x="793" y="178"><field name="COMMENT">...links500 zum Einsatz</field></block><block type="basic_comment" id="Hmng;OxB6LEyk8z@@{+V" x="1118" y="167"><field name="COMMENT">leuchte grün</field></block><block type="procedures_defnoreturn" id="!~O3Z@ml~lm7V[RbKOy6" x="1247" y="251"><field name="NAME">rueck500 mit Pixel Weiss</field><statement name="STACK"><block type="motor_write_percentage" id="W]23SNy.3ba8hPM)Y#20"><value name="MOTOR"><block type="motor_pin" id=",km+FnQe7/e#nyYX}}uq"><field name="MOTOR">MOTOR1</field></block></value><value name="PERCENTAGE"><block type="math_number" id="NLS^=rexTIRnE?66y)?v"><field name="NUM">-100</field></block></value><next><block type="motor_write_percentage" id="z]X_2nxS#]y1TVe`RoaT"><value name="MOTOR"><block type="motor_pin" id="8_v/]7%A@1]^=LI/g_j["><field name="MOTOR">MOTOR2</field></block></value><value name="PERCENTAGE"><block type="math_number" id="-u~P8wt^1DEMD;;u5Pmb"><field name="NUM">-100</field></block></value><next><block type="set_pixel_color" id="op4]zXqQ740Wy=-Tf5Re"><field name="MODE">MODE1</field><value name="FROM"><block type="math_number" id="=+l%)=5nah;BgnAcFp}_"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number" id="`W0FB_$5kj$%cdcr5a!."><field name="NUM">16</field></block></value><value name="H"><block type="math_number" id="g$Q-I@s{`37V)S5I3Cn-"><field name="NUM">0</field></block></value><value name="S"><block type="math_number" id="gCr^hUl|=J)xGG^x3mZ*"><field name="NUM">0</field></block></value><value name="B"><block type="math_number" id="9#(;Rvi.R2^li^zXy/Ja"><field name="NUM">100</field></block></value><next><block type="flow_delay" id="3U:W^vI~=zMn5|@l;J01"><value name="DELAY"><block type="math_number" id="mo-@wImU1_pF*yb!Hlc="><field name="NUM">500</field></block></value></block></next></block></next></block></next></block></statement></block><block type="basic_comment" id="t@,a,8O|SOBo1gWT8qD+" x="1116" y="368"><field name="COMMENT">leuchte weiss</field></block><block type="procedures_defnoreturn" id="n6XT0eQ|^EgjUXtmm@;c" x="1252" y="496"><field name="NAME">links500 mit Pixellauflicht orange</field><statement name="STACK"><block type="motor_write_percentage" id="L]fgJ/C}8#B!oV[8|o+?"><value name="MOTOR"><block type="motor_pin" id="@*;@{{3yVo*0J[VwK)u#"><field name="MOTOR">MOTOR1</field></block></value><value name="PERCENTAGE"><block type="math_number" id="2#MLNz.mO[EzMQVWRG4."><field name="NUM">60</field></block></value><next><block type="motor_write_percentage" id="0cmykxCjrzIv}Prnxm]E"><value name="MOTOR"><block type="motor_pin" id="g.CREhghO,#/`=o[/dpI"><field name="MOTOR">MOTOR2</field></block></value><value name="PERCENTAGE"><block type="math_number" id="gQL?|C)bPTC{-AA1Wre_"><field name="NUM">-60</field></block></value><next><block type="flow_for" id="G17i{TFU}l#4|y$xN_t#"><field name="VAR" id="$?@G1IQZ5n8rPS$T16dY">Pixel</field><value name="FROM"><block type="math_number" id="p/t^x7caYxi^MJXgs@?Q"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number" id="ep%[_C82k=pH{Rg5aP0L"><field name="NUM">16</field></block></value><value name="BY"><block type="math_number" id="Uv5BkvOy@RBO_%8~%DdE"><field name="NUM">1</field></block></value><statement name="DO"><block type="set_pixel_color" id="]]@^`J_Fw60v;HUzfV=U"><field name="MODE">MODE1</field><value name="FROM"><block type="variables_get" id="#7IG:6=n+_.BzB6wCb#,"><field name="VAR" id="$?@G1IQZ5n8rPS$T16dY">Pixel</field></block></value><value name="TO"><block type="math_number" id="2{Cj:7A=K:|QP4!;F$pZ"><field name="NUM">1</field></block></value><value name="H"><block type="math_number" id="SflO:UBGF)2cJ*pP8`Q*"><field name="NUM">20</field></block></value><value name="S"><block type="math_number" id=".-q?S2xZNq(H-H*@|N(2"><field name="NUM">100</field></block></value><value name="B"><block type="math_number" id="p.u+#;DKPyySbI0d!9a%"><field name="NUM">100</field></block></value><next><block type="flow_delay" id="o[G;wsJ|KpmH?k5zMTAI"><value name="DELAY"><block type="math_number" id="OQu^YP{/O04N(yE4ZEtR"><field name="NUM">33</field></block></value></block></next></block></statement></block></next></block></next></block></statement></block><block type="basic_comment" id=";[ab`]COLD6|1Uq7`we6" x="1107" y="620"><field name="COMMENT">Lauflicht orange</field></block><block type="procedures_defnoreturn" id="=%q9Bj*vb@hrq(4|mdMu" x="1253" y="794"><field name="NAME">rechts500 mit Pixellauflicht orange</field><statement name="STACK"><block type="motor_write_percentage" id="vEE2=!D,#uW]sV^gxhud"><value name="MOTOR"><block type="motor_pin" id="1ynquHyGZij_Pe1`zX}L"><field name="MOTOR">MOTOR1</field></block></value><value name="PERCENTAGE"><block type="math_number" id="X]|ShOGCpF#)rzSS!p!Q"><field name="NUM">-60</field></block></value><next><block type="motor_write_percentage" id="b]5|R*d1f8uT||-{C(`C"><value name="MOTOR"><block type="motor_pin" id="9:n*VpUAP9FW|4Kz`9.-"><field name="MOTOR">MOTOR2</field></block></value><value name="PERCENTAGE"><block type="math_number" id="^/J%^-*^aIDFOy-yxuHT"><field name="NUM">60</field></block></value><next><block type="flow_for" id="$[X,|*v@*!FE~g^2Fi#V"><field name="VAR" id="$?@G1IQZ5n8rPS$T16dY">Pixel</field><value name="FROM"><block type="math_number" id="/1~?-m(F5f{sg_y3(FfH"><field name="NUM">16</field></block></value><value name="TO"><block type="math_number" id="|OnB()kZ^wI-Z%?bx}ko"><field name="NUM">1</field></block></value><value name="BY"><block type="math_number" id="B?ta.Ff/r#a[dgmgy^kt"><field name="NUM">1</field></block></value><statement name="DO"><block type="set_pixel_color" id="H1~~`1ooEX5*Z)V_RMHN"><field name="MODE">MODE1</field><value name="FROM"><block type="variables_get" id="i$kmxSTmISSm8NJP}Col"><field name="VAR" id="$?@G1IQZ5n8rPS$T16dY">Pixel</field></block></value><value name="TO"><block type="math_number" id="Eh!vv,7ZHe#F/$o:V;%n"><field name="NUM">1</field></block></value><value name="H"><block type="math_number" id="WupFr1Fdv/a*dGDRJk_o"><field name="NUM">20</field></block></value><value name="S"><block type="math_number" id="L8coG:OImL}6=Pvj[gU$"><field name="NUM">100</field></block></value><value name="B"><block type="math_number" id="Uy*57Fk*[C`sr=t6%8QZ"><field name="NUM">100</field></block></value><next><block type="flow_delay" id="qUs=:anQrX^V,FJz{NO("><value name="DELAY"><block type="math_number" id=";^,!H2Zqf4T#hhHR*3)9"><field name="NUM">33</field></block></value></block></next></block></statement></block></next></block></next></block></statement></block><block type="basic_comment" id="E1`~M!H[!$FZ(Cx0I%bK" x="1044" y="917"><field name="COMMENT">Lauflicht orange rückwärts</field></block></xml>

Anforderung:
✓ Einfach bis mittel
✓ Bauen ohne Werkstatt
✓ Mehrmals bauen und zerlegen

Thema:
> Sensor steuert Motor
> Sensor steuert Licht
> Einfacher Programmablauf mit Bedingung
> LED und Neopixel

Werkzeug:
> Lötstation

Material:
> Bausatz pglu.ch/shop > Arduino Roboter
> pglu.ch/shop > Mikrocontroller KOMFORT oder MOTOR
> pglu.ch/shop > Elektronik > LED und MATRIX

Anleitung Roboter:
> Roboter bauen: TTG PROJEKT > ARDUINO ROBOTER > BAU
> Elektronik anschliessen: TTG PROJEKT > ARDUINO ROBOTER > BAU
> Roboter programmieren: TTG PROJEKT> ARDUINO ROBOTER > CODING

Anleitung LED & Neopixel
> LEDs anschliessen: workshop.pglu.ch > Aktor > LED
> Neopixel anschliessen: TTG PROJEKT > NEOPIXEL > BAU

3D-Modell:
> Hier anschauen

Videos:
> Roboter Fahrfunktionen: TTG PROJEKT > ARDUINO ROBOTER > CODING > VIDEO
> Neopixel Matrix: TTG PROJEKT > NEOPIXEL MATRIX > CODING

Basics:
> Lernumgebung aufbauen: pglu.ch > ANLEITUNG
> XML in Editor importieren: pglu.ch > ANLEITUNG > EDITOR

Editor:
> Online: mach.pglu.ch
> Teacher’s Box: mach.pglu.box

Erweiterungen:
> Matrix Designer: TTG PROJEKT > NEOPIXEL MATRIX > CODING
> Ultraschallsensor: workshop.pglu.ch > SENSOR
> Weiteres: pglu.ch > HILFREICHE DOKUMENTE
> Erweiterung mit KI: ki-kit.ch