3 – Schranklicht Challenge: bring Licht in deinen Kleiderschrank
Schranklicht Challenge: bring Licht in deinen Kleiderschrank
Das lernst du hier
Das kennst du sicher: am Morgen nach dem Aufstehen greifst du in den Kleiderschrank, ohne richtig zu sehen, was du gerade herausziehst. Das Ergebnis ist ein Chaos in deinen Kleidern 😣.
Mit dieser Challenge bringst du Licht in deine Ablage und kreierst erst noch einen luxeriösen Dimmeffekt beim Öffnen der Schranktür. Was für ein Start in den Tag 🙂!

Ultraschallsensor verstehen
Wie geht das?
Ein Ultraschallsensor ist ein spezielles Messgerät, welches die Distanz zu einem Gegenstand messen kann. Obwohl der Sensor optisch an ein Augenpaar erinnert, besteht er in Wahrheit aus einem Lautsprecher und einem Mikrofon. Damit sendet er sehr hohe Töne aus und misst die Zeit, die verstreicht, bis er das Echo dieser Töne wieder hören kann. Wie das funktioniert, kann uns die Tierwelt am besten erklären, denn Fledermäuse aber auch Delphine orientieren sich mit dieser Methode in der Luft oder im Wasser.
Weitere Infos zum Ultraschallsensor und wie du ihn mit dem Arduino programmierst, findest du hier.
Ultraschallsensor und Neopixel Matrix anschliessen

Neopixel Matrix in Schrank oder Schulblade befestigen und Sensor ausrichten
Befestige die Neopixel Matrix mit etwas Malerklebband in einem Schrank oder einer Schublade, die du beleuchten möchtest. Richte dann den Sensor so aus, dass er die Tür des Schranks als Objekt erkennen kann und anhand von der Distanz merkt, ob diese geöffnet oder geschlossen ist. Der Messbereich des Ultraschallsensors beträgt 3cm bis ca. 400cm:
Distanzerkennung programmieren und optimieren
Die Funktion des Programms ist schnell erklärt, denn der Sensor schaltet die 16 Pixel ein, sobald er eine Distanz misst, die grösser ist als ein bestimmter Wert. Wenn du die Videos oben anschaust, verstehst du das schnell.
Die beiden Sketches unten sind als Vorschläge gedacht, denn du kannst sie optimieren und an deine Bedürfnisse anpassen. Ändere die Farbe des Lichts oder die Geschwindigkeit des Schalteffekts, indem du Pausen einbaust!
Challenge:
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="Fgi(boC*F5V:]r|tcnW,">Distanz in cm</variable><variable id="w#g|TWs[|tK%g)vcs!n5">Verstrichene Zeit</variable></variables><block type="basic_comment" id="H~UW;?gR9HL56l!+P|SL" x="-131" y="-123"><field name="COMMENT">Schranktür Challenge mit Dimmer</field></block><block type="set_neo_pixel" id="!Om9r{B%q#Ax%A]Do=O0" x="-131" y="-37"><value name="NUM_LEDS"><block type="math_number" id="sGg3N3FKmd)8(6;uEI{*"><field name="NUM">16</field></block></value><value name="BRIGHTNESS"><block type="math_number" id="W2KAj#}-gE`P}9v*v)3B"><field name="NUM">100</field></block></value><value name="OUTTURN"><block type="led_pin" id="9-MqZA.)f?Uo,GG(]b7X"><field name="LED">LED1</field></block></value></block><block type="basic_comment" id="|.$x+yKiz`j-,~[?eRLs" x="-700" y="32"><field name="COMMENT">Nicht löschen, dies ist die Ultraschallsensor Funktion</field></block><block type="basic_main_loop" id="9~210UV)!{|GniQxFn|[" deletable="false" x="-131" y="37"><value name="BLINK"><block type="basic_blinkcode" id="u@6%knhMhK2g(1JYw[10"><field name="SHORT">1</field><field name="LONG">1</field></block></value></block><block type="procedures_defreturn" id="VnG.[Xi?K@xVOSmR%A:Q" collapsed="true" x="-698" y="84"><field name="NAME">Gemessene Distanz in cm</field><statement name="STACK"><block type="led_write_state" id="(YnUm|J,9fsc(p4r9s;7"><value name="LED"><block type="led_pin" id="H.T)=mm`Ifwv2Fhc|S2f"><field name="LED">LED3</field></block></value><value name="VALUE"><block type="code_pin" id="2?t[*AxO#`+[63!Kbv|4"><field name="CODE_PIN">LOW</field></block></value><next><block type="flow_delay_micro" id="wg)XFQj(bZQ@7;s8Xn)g"><value name="DELAY_MICRO"><block type="math_number" id="+-ylq#`F5bV2s=I1tqw5"><field name="NUM">2</field></block></value><next><block type="led_write_state" id="^{tG^[d%-ztHVl2chmz3"><value name="LED"><block type="led_pin" id="v*lb+hhl[Wi(7pV0Rh2Y"><field name="LED">LED3</field></block></value><value name="VALUE"><block type="code_pin" id="W@AYsU^fM(0P#-M5(rD5"><field name="CODE_PIN">HIGH</field></block></value><next><block type="flow_delay_micro" id="b1cIi4)J^l_l*FFQ9YDW"><value name="DELAY_MICRO"><block type="math_number" id=";%*_lC[QmT=aFvU2dBmT"><field name="NUM">10</field></block></value><next><block type="led_write_state" id=")#=atR)n~|WSuN9-h*qS"><value name="LED"><block type="led_pin" id="vt(XIF^r7P4^(:[t9(|Y"><field name="LED">LED3</field></block></value><value name="VALUE"><block type="code_pin" id="mC9fceq(Z!8lgrV}*q#s"><field name="CODE_PIN">LOW</field></block></value><next><block type="variables_set" id="abkprn]D|R;FJkV?c1X%"><field name="VAR" id="w#g|TWs[|tK%g)vcs!n5">Verstrichene Zeit</field><value name="VALUE"><block type="code_pin" id="^l1C}Yuf?uC!$*grR2(~"><field name="CODE_PIN">pulseIn(16, HIGH)</field></block></value><next><block type="flow_delay" id="^~$p)C+|`cXjw=]|)4vk"><value name="DELAY"><block type="math_number" id="e`),5T9$86+YFbpttWJ4"><field name="NUM">5</field></block></value><next><block type="variables_set" id="%KSHJ,gWN(m1+Bf15WL-"><field name="VAR" id="Fgi(boC*F5V:]r|tcnW,">Distanz in cm</field><value name="VALUE"><block type="math_arithmetic" id="H!$n-us!:]A80ihl_Z)M"><field name="OP">MULTIPLY</field><value name="A"><block type="variables_get" id="5jMKhuU|jo^bbm)GwQ7-"><field name="VAR" id="w#g|TWs[|tK%g)vcs!n5">Verstrichene Zeit</field></block></value><value name="B"><block type="math_number" id="eWh9Q^v9;dBK`FlU1YC]"><field name="NUM">0.0175</field></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement><value name="RETURN"><block type="variables_get" id="^0,i^h8Sw0}Qz*WLV`X{"><field name="VAR" id="Fgi(boC*F5V:]r|tcnW,">Distanz in cm</field></block></value></block><block type="set_pixel_color" id=",q%~kDEJ-i39DEs4U,!y" x="-132" y="196"><field name="MODE">MODE1</field><value name="FROM"><block type="math_number" id="0;kZ.@whgu3/7Uk%_Y(V"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number" id="seWvF~|!zu1EaCd5;])U"><field name="NUM">16</field></block></value><value name="H"><block type="math_number" id="{q+:s-7Yu180O;X(dAZV"><field name="NUM">40</field></block></value><value name="S"><block type="math_number" id="0h5?qRETqCQ=PdMoexV`"><field name="NUM">80</field></block></value></block><block type="set_pixel_color" id="MdNcLJ(BO_zz5W`+i$!@" x="-128" y="293"><field name="MODE">MODE1</field><value name="FROM"><block type="math_number" id="=Y:nR%[?|}$Dy2M^Zt$z"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number" id="cl:RX,*Pbdic)y2#bDqs"><field name="NUM">16</field></block></value><value name="H"><block type="math_number" id="1uIq79Hhwt}jmz|M)u:0"><field name="NUM">40</field></block></value><value name="S"><block type="math_number" id="OZD6;GG{Ep-f3V*6B.3p"><field name="NUM">80</field></block></value></block><block type="logic_if" id="=}ykQxHO}QTNpu]oo?/:" x="-125" y="382"><mutation xmlns="http://www.w3.org/1999/xhtml" else="1"></mutation></block><block type="logic_compare" id="6(YiA9nyDNW^skN?3nvD" x="-129" y="528"><field name="OP">GT</field></block><block type="math_number" id="KQt5Do|Ei73@zmZYSo^!" x="-124" y="601"><field name="NUM">100</field></block><block type="math_number" id="Pjy`]qRq$AeD;sCJ9*YZ" x="-32" y="602"><field name="NUM">30</field></block><block type="math_number" id="9nW@zFR(No?Ar,^zEb8w" x="47" y="602"><field name="NUM">0</field></block><block type="procedures_callreturn" id="rsV|bayB4USpXT9IsJ/l" x="-124" y="654"><mutation name="Gemessene Distanz in cm"></mutation></block></xml>
Mögliche Lösung:
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="Fgi(boC*F5V:]r|tcnW,">Distanz in cm</variable><variable id="w#g|TWs[|tK%g)vcs!n5">Verstrichene Zeit</variable></variables><block type="basic_comment" id="H~UW;?gR9HL56l!+P|SL" x="-131" y="-123"><field name="COMMENT">Schranktür Challenge mit Dimmer</field></block><block type="set_neo_pixel" id="!Om9r{B%q#Ax%A]Do=O0" x="-131" y="-37"><value name="NUM_LEDS"><block type="math_number" id="sGg3N3FKmd)8(6;uEI{*"><field name="NUM">16</field></block></value><value name="BRIGHTNESS"><block type="math_number" id="W2KAj#}-gE`P}9v*v)3B"><field name="NUM">100</field></block></value><value name="OUTTURN"><block type="led_pin" id="9-MqZA.)f?Uo,GG(]b7X"><field name="LED">LED1</field></block></value></block><block type="basic_comment" id="|.$x+yKiz`j-,~[?eRLs" x="-700" y="32"><field name="COMMENT">Nicht löschen, dies ist die Ultraschallsensor Funktion</field></block><block type="basic_main_loop" id="9~210UV)!{|GniQxFn|[" deletable="false" x="-131" y="37"><value name="BLINK"><block type="basic_blinkcode" id="u@6%knhMhK2g(1JYw[10"><field name="SHORT">1</field><field name="LONG">1</field></block></value><statement name="CODE"><block type="logic_if" id="=}ykQxHO}QTNpu]oo?/:"><mutation xmlns="http://www.w3.org/1999/xhtml" else="1"></mutation><value name="IF0"><block type="logic_compare" id="6(YiA9nyDNW^skN?3nvD"><field name="OP">GT</field><value name="A"><block type="procedures_callreturn" id="rsV|bayB4USpXT9IsJ/l"><mutation name="Gemessene Distanz in cm"></mutation></block></value><value name="B"><block type="math_number" id="Pjy`]qRq$AeD;sCJ9*YZ"><field name="NUM">28</field></block></value></block></value><statement name="DO0"><block type="set_pixel_color" id="MdNcLJ(BO_zz5W`+i$!@"><field name="MODE">MODE1</field><value name="FROM"><block type="math_number" id="=Y:nR%[?|}$Dy2M^Zt$z"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number" id="cl:RX,*Pbdic)y2#bDqs"><field name="NUM">16</field></block></value><value name="H"><block type="math_number" id="1uIq79Hhwt}jmz|M)u:0"><field name="NUM">40</field></block></value><value name="S"><block type="math_number" id="OZD6;GG{Ep-f3V*6B.3p"><field name="NUM">80</field></block></value><value name="B"><block type="math_number" id="KQt5Do|Ei73@zmZYSo^!"><field name="NUM">100</field></block></value></block></statement><statement name="ELSE"><block type="set_pixel_color" id=",q%~kDEJ-i39DEs4U,!y"><field name="MODE">MODE1</field><value name="FROM"><block type="math_number" id="0;kZ.@whgu3/7Uk%_Y(V"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number" id="seWvF~|!zu1EaCd5;])U"><field name="NUM">16</field></block></value><value name="H"><block type="math_number" id="{q+:s-7Yu180O;X(dAZV"><field name="NUM">40</field></block></value><value name="S"><block type="math_number" id="0h5?qRETqCQ=PdMoexV`"><field name="NUM">80</field></block></value><value name="B"><block type="math_number" id="9nW@zFR(No?Ar,^zEb8w"><field name="NUM">0</field></block></value></block></statement></block></statement></block><block type="procedures_defreturn" id="VnG.[Xi?K@xVOSmR%A:Q" collapsed="true" x="-698" y="84"><field name="NAME">Gemessene Distanz in cm</field><statement name="STACK"><block type="led_write_state" id="(YnUm|J,9fsc(p4r9s;7"><value name="LED"><block type="led_pin" id="H.T)=mm`Ifwv2Fhc|S2f"><field name="LED">LED3</field></block></value><value name="VALUE"><block type="code_pin" id="2?t[*AxO#`+[63!Kbv|4"><field name="CODE_PIN">LOW</field></block></value><next><block type="flow_delay_micro" id="wg)XFQj(bZQ@7;s8Xn)g"><value name="DELAY_MICRO"><block type="math_number" id="+-ylq#`F5bV2s=I1tqw5"><field name="NUM">2</field></block></value><next><block type="led_write_state" id="^{tG^[d%-ztHVl2chmz3"><value name="LED"><block type="led_pin" id="v*lb+hhl[Wi(7pV0Rh2Y"><field name="LED">LED3</field></block></value><value name="VALUE"><block type="code_pin" id="W@AYsU^fM(0P#-M5(rD5"><field name="CODE_PIN">HIGH</field></block></value><next><block type="flow_delay_micro" id="b1cIi4)J^l_l*FFQ9YDW"><value name="DELAY_MICRO"><block type="math_number" id=";%*_lC[QmT=aFvU2dBmT"><field name="NUM">10</field></block></value><next><block type="led_write_state" id=")#=atR)n~|WSuN9-h*qS"><value name="LED"><block type="led_pin" id="vt(XIF^r7P4^(:[t9(|Y"><field name="LED">LED3</field></block></value><value name="VALUE"><block type="code_pin" id="mC9fceq(Z!8lgrV}*q#s"><field name="CODE_PIN">LOW</field></block></value><next><block type="variables_set" id="abkprn]D|R;FJkV?c1X%"><field name="VAR" id="w#g|TWs[|tK%g)vcs!n5">Verstrichene Zeit</field><value name="VALUE"><block type="code_pin" id="^l1C}Yuf?uC!$*grR2(~"><field name="CODE_PIN">pulseIn(16, HIGH)</field></block></value><next><block type="flow_delay" id="^~$p)C+|`cXjw=]|)4vk"><value name="DELAY"><block type="math_number" id="e`),5T9$86+YFbpttWJ4"><field name="NUM">5</field></block></value><next><block type="variables_set" id="%KSHJ,gWN(m1+Bf15WL-"><field name="VAR" id="Fgi(boC*F5V:]r|tcnW,">Distanz in cm</field><value name="VALUE"><block type="math_arithmetic" id="H!$n-us!:]A80ihl_Z)M"><field name="OP">MULTIPLY</field><value name="A"><block type="variables_get" id="5jMKhuU|jo^bbm)GwQ7-"><field name="VAR" id="w#g|TWs[|tK%g)vcs!n5">Verstrichene Zeit</field></block></value><value name="B"><block type="math_number" id="eWh9Q^v9;dBK`FlU1YC]"><field name="NUM">0.0175</field></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement><value name="RETURN"><block type="variables_get" id="^0,i^h8Sw0}Qz*WLV`X{"><field name="VAR" id="Fgi(boC*F5V:]r|tcnW,">Distanz in cm</field></block></value></block></xml>
Wie gewohnt in der Programmierung, gibt es für jedes Problem verschiedene Lösungen. Der Sketch unten zeigt dir als Beispiel, wie ein Dimmeffekt programmiert werden könnte. Versuche dabei die Variable HELLIGKEIT zu verstehen und die Funktion BEGRENZE…
Spiele mit dem Farben und dem Tempo des Effekts.
Challenge erweitert:
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="hh-(4|Ko.^/L}~6wn!lW">Helligkeit</variable><variable id="_7ye.we37|x%yj+NX6/w">Distanz in cm</variable><variable id="UrX!`o6_?c0KL{pT_~F+">Verstrichene Zeit</variable></variables><block type="set_neo_pixel" id=")qSh7+_y{ylTv4rX-A#o" x="1041" y="-229"><value name="NUM_LEDS"><block type="math_number" id="/ld*~I:+Dd,sh7x$d@Sz"><field name="NUM">16</field></block></value><value name="BRIGHTNESS"><block type="math_number" id="Nl$Ra:Zv1I~Od#^pEk7w"><field name="NUM">100</field></block></value><value name="OUTTURN"><block type="led_pin" id="qd|m%IE|;o_+Qk(r]l(R"><field name="LED">LED1</field></block></value></block><block type="basic_comment" id="Q1Y6q|FJ8tEi~7/zT:fj" x="593" y="-141"><field name="COMMENT">Funktion für den Ultraschallsensor</field></block><block type="basic_main_loop" id="oh{4)]E/c6ZnlvMJU:hx" deletable="false" x="1042" y="-146"><value name="BLINK"><block type="basic_blinkcode" id="30Q8]G`cyw:$0tmjHjkl"><field name="SHORT">1</field><field name="LONG">1</field></block></value></block><block type="procedures_defreturn" id="TBvQ8Sr=*[TcvQX9^5_J" collapsed="true" x="595" y="-85"><field name="NAME">gemessene Distanz in cm</field><statement name="STACK"><block type="led_write_state" id="(kj]~+1/ZFD0US:vu-*9"><value name="LED"><block type="led_pin" id="blZ0%tdcGI]JLQip1_RQ"><field name="LED">LED3</field></block></value><value name="VALUE"><block type="code_pin" id="orLh,)iv},r24Zs2+}!#"><field name="CODE_PIN">LOW</field></block></value><next><block type="flow_delay_micro" id="S[MmRI*@Hj1i}YC.[rd5"><value name="DELAY_MICRO"><block type="math_number" id="OfzdI8hp.c(%SdaI?}ZS"><field name="NUM">2</field></block></value><next><block type="led_write_state" id="@eZs~I(SS/:jD496}g@*"><value name="LED"><block type="led_pin" id="(qbN4yE{@?e;ClO[#jz6"><field name="LED">LED3</field></block></value><value name="VALUE"><block type="code_pin" id="bizQ^Ka}3DZRPxWw,0j$"><field name="CODE_PIN">HIGH</field></block></value><next><block type="flow_delay_micro" id="-M=T~=Td6N9}!+hC;0]w"><value name="DELAY_MICRO"><block type="math_number" id="]fZ#|4D9|QJ4PEuFZs[t"><field name="NUM">10</field></block></value><next><block type="led_write_state" id="C%X#}aI^]Ta^@KcET+;4"><value name="LED"><block type="led_pin" id="MUPm9sh#.CL84)SL.1;!"><field name="LED">LED3</field></block></value><value name="VALUE"><block type="code_pin" id="2f1)Vqr@ka]N!?t(^wxZ"><field name="CODE_PIN">LOW</field></block></value><next><block type="variables_set" id="[qW|t_GpnW%[y%5AaYUg"><field name="VAR" id="UrX!`o6_?c0KL{pT_~F+">Verstrichene Zeit</field><value name="VALUE"><block type="code_pin" id="H#gT/;^m5CrQnF{WR+;7"><field name="CODE_PIN">pulseIn(16, HIGH)</field></block></value><next><block type="variables_set" id="vFnXw[RWuqq].BUHDP8F"><field name="VAR" id="_7ye.we37|x%yj+NX6/w">Distanz in cm</field><value name="VALUE"><block type="code_pin" id="Qc3n[]3qr@Uy9.DJ`)N_"><field name="CODE_PIN">(Verstrichene_Zeit*0.0343)/2</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></statement><value name="RETURN"><block type="variables_get" id=")r}C!FTab-Y:c^j2$u!#"><field name="VAR" id="_7ye.we37|x%yj+NX6/w">Distanz in cm</field></block></value></block><block type="procedures_callreturn" id="8#z0@:2HWPo~A4cUrMCy" x="1030" y="-45"><mutation name="gemessene Distanz in cm"></mutation></block><block type="variables_set" id="$.CmP)6AMz@6Hv7Ahs)N" x="1038" y="32"><field name="VAR" id="hh-(4|Ko.^/L}~6wn!lW">Helligkeit</field><value name="VALUE"><block type="math_constrain" id="IQSU/qnuf[Q/pgi@|,J2"><value name="VALUE"><block type="math_arithmetic" id="L@z![,G17nZ=k*t~|3@I"><field name="OP">ADD</field><value name="A"><block type="variables_get" id="F*[#nHl5+g=~JW7+MieF"><field name="VAR" id="hh-(4|Ko.^/L}~6wn!lW">Helligkeit</field></block></value><value name="B"><block type="math_number" id="ri?C@_NeE0{F.1+TN5=~"><field name="NUM">0.5</field></block></value></block></value><value name="MIN"><block type="math_number" id="Z[lY-haxMR4i+PWlc5Z-"><field name="NUM">0</field></block></value><value name="MAX"><block type="math_number" id="#Yjl15Dl`-,).K$dhY,C"><field name="NUM">100</field></block></value></block></value></block><block type="logic_if" id="C$j0Zv$.=|NlKvF1T-SZ" x="1798" y="32"><mutation xmlns="http://www.w3.org/1999/xhtml" else="1"></mutation></block><block type="variables_set" id="H`Qi-hMUhycl8]1,E#]}" x="1033" y="134"><field name="VAR" id="hh-(4|Ko.^/L}~6wn!lW">Helligkeit</field><value name="VALUE"><block type="math_constrain" id="897ZGBMM=!7NoDgu?y6s"><value name="VALUE"><block type="math_arithmetic" id="zL1W8I9G5}54[he[pwmq"><field name="OP">MINUS</field><value name="A"><block type="variables_get" id="o)Ux+@5iJ{^0:q`hhMxt"><field name="VAR" id="hh-(4|Ko.^/L}~6wn!lW">Helligkeit</field></block></value><value name="B"><block type="math_number" id="o%5K,CXAng*d,cKx0NK,"><field name="NUM">1</field></block></value></block></value><value name="MIN"><block type="math_number" id="qp+^Vu:pJk]F8!$9@ih]"><field name="NUM">0</field></block></value><value name="MAX"><block type="math_number" id=",N]w![a-ChgIO#+R8_Q5"><field name="NUM">100</field></block></value></block></value></block><block type="set_pixel_color" id="9G$f[LQKnWH-x%#K!:2K" x="1032" y="243"><field name="MODE">MODE1</field><value name="FROM"><block type="math_number" id="1/ifCe)/iP89.O;V?5]S"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number" id="siX?jv.SmBH=EF+x[NK#"><field name="NUM">16</field></block></value><value name="H"><block type="math_number" id="fR+J!Zx!iv{ZBv-#U6)N"><field name="NUM">40</field></block></value><value name="S"><block type="math_number" id="wz#13uyX[WpOK%Ag...W"><field name="NUM">70</field></block></value><value name="B"><block type="variables_get" id="d;|1dMPzR)0c(4qBB]=g"><field name="VAR" id="hh-(4|Ko.^/L}~6wn!lW">Helligkeit</field></block></value><next><block type="flow_delay" id="XV7[z|2,1P#Os/^VN/wg"><value name="DELAY"><block type="math_number" id="CH3qbaS`gr)%imhmlg+:"><field name="NUM">10</field></block></value></block></next></block><block type="logic_compare" id="hj.4+qA1G!{=/qcL5yx1" x="1029" y="377"><field name="OP">GT</field><value name="B"><block type="math_number" id="4DD5GN!Ym_W*Oa[dBgjw"><field name="NUM">30</field></block></value></block></xml>
Mögliche Lösung:
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="_7ye.we37|x%yj+NX6/w">Distanz in cm</variable><variable id="hh-(4|Ko.^/L}~6wn!lW">Helligkeit</variable><variable id="UrX!`o6_?c0KL{pT_~F+">Verstrichene Zeit</variable></variables><block type="set_neo_pixel" id=")qSh7+_y{ylTv4rX-A#o" x="1041" y="-229"><value name="NUM_LEDS"><block type="math_number" id="/ld*~I:+Dd,sh7x$d@Sz"><field name="NUM">16</field></block></value><value name="BRIGHTNESS"><block type="math_number" id="Nl$Ra:Zv1I~Od#^pEk7w"><field name="NUM">100</field></block></value><value name="OUTTURN"><block type="led_pin" id="qd|m%IE|;o_+Qk(r]l(R"><field name="LED">LED1</field></block></value></block><block type="basic_comment" id="Q1Y6q|FJ8tEi~7/zT:fj" x="593" y="-141"><field name="COMMENT">Funktion für den Ultraschallsensor</field></block><block type="basic_main_loop" id="oh{4)]E/c6ZnlvMJU:hx" deletable="false" x="1042" y="-146"><value name="BLINK"><block type="basic_blinkcode" id="30Q8]G`cyw:$0tmjHjkl"><field name="SHORT">1</field><field name="LONG">1</field></block></value><statement name="CODE"><block type="logic_if" id="C$j0Zv$.=|NlKvF1T-SZ"><mutation xmlns="http://www.w3.org/1999/xhtml" else="1"></mutation><value name="IF0"><block type="logic_compare" id="hj.4+qA1G!{=/qcL5yx1"><field name="OP">GT</field><value name="A"><block type="procedures_callreturn" id="8#z0@:2HWPo~A4cUrMCy"><mutation name="gemessene Distanz in cm"></mutation></block></value><value name="B"><block type="math_number" id="4DD5GN!Ym_W*Oa[dBgjw"><field name="NUM">30</field></block></value></block></value><statement name="DO0"><block type="variables_set" id="$.CmP)6AMz@6Hv7Ahs)N"><field name="VAR" id="hh-(4|Ko.^/L}~6wn!lW">Helligkeit</field><value name="VALUE"><block type="math_constrain" id="IQSU/qnuf[Q/pgi@|,J2"><value name="VALUE"><block type="math_arithmetic" id="L@z![,G17nZ=k*t~|3@I"><field name="OP">ADD</field><value name="A"><block type="variables_get" id="F*[#nHl5+g=~JW7+MieF"><field name="VAR" id="hh-(4|Ko.^/L}~6wn!lW">Helligkeit</field></block></value><value name="B"><block type="math_number" id="ri?C@_NeE0{F.1+TN5=~"><field name="NUM">0.5</field></block></value></block></value><value name="MIN"><block type="math_number" id="Z[lY-haxMR4i+PWlc5Z-"><field name="NUM">0</field></block></value><value name="MAX"><block type="math_number" id="#Yjl15Dl`-,).K$dhY,C"><field name="NUM">100</field></block></value></block></value></block></statement><statement name="ELSE"><block type="variables_set" id="H`Qi-hMUhycl8]1,E#]}"><field name="VAR" id="hh-(4|Ko.^/L}~6wn!lW">Helligkeit</field><value name="VALUE"><block type="math_constrain" id="897ZGBMM=!7NoDgu?y6s"><value name="VALUE"><block type="math_arithmetic" id="zL1W8I9G5}54[he[pwmq"><field name="OP">MINUS</field><value name="A"><block type="variables_get" id="o)Ux+@5iJ{^0:q`hhMxt"><field name="VAR" id="hh-(4|Ko.^/L}~6wn!lW">Helligkeit</field></block></value><value name="B"><block type="math_number" id="o%5K,CXAng*d,cKx0NK,"><field name="NUM">1</field></block></value></block></value><value name="MIN"><block type="math_number" id="qp+^Vu:pJk]F8!$9@ih]"><field name="NUM">0</field></block></value><value name="MAX"><block type="math_number" id=",N]w![a-ChgIO#+R8_Q5"><field name="NUM">100</field></block></value></block></value></block></statement><next><block type="set_pixel_color" id="9G$f[LQKnWH-x%#K!:2K"><field name="MODE">MODE1</field><value name="FROM"><block type="math_number" id="1/ifCe)/iP89.O;V?5]S"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number" id="siX?jv.SmBH=EF+x[NK#"><field name="NUM">16</field></block></value><value name="H"><block type="math_number" id="fR+J!Zx!iv{ZBv-#U6)N"><field name="NUM">40</field></block></value><value name="S"><block type="math_number" id="wz#13uyX[WpOK%Ag...W"><field name="NUM">70</field></block></value><value name="B"><block type="variables_get" id="d;|1dMPzR)0c(4qBB]=g"><field name="VAR" id="hh-(4|Ko.^/L}~6wn!lW">Helligkeit</field></block></value><next><block type="flow_delay" id="XV7[z|2,1P#Os/^VN/wg"><value name="DELAY"><block type="math_number" id="CH3qbaS`gr)%imhmlg+:"><field name="NUM">10</field></block></value></block></next></block></next></block></statement></block><block type="procedures_defreturn" id="TBvQ8Sr=*[TcvQX9^5_J" collapsed="true" x="595" y="-85"><field name="NAME">gemessene Distanz in cm</field><statement name="STACK"><block type="led_write_state" id="(kj]~+1/ZFD0US:vu-*9"><value name="LED"><block type="led_pin" id="blZ0%tdcGI]JLQip1_RQ"><field name="LED">LED3</field></block></value><value name="VALUE"><block type="code_pin" id="orLh,)iv},r24Zs2+}!#"><field name="CODE_PIN">LOW</field></block></value><next><block type="flow_delay_micro" id="S[MmRI*@Hj1i}YC.[rd5"><value name="DELAY_MICRO"><block type="math_number" id="OfzdI8hp.c(%SdaI?}ZS"><field name="NUM">2</field></block></value><next><block type="led_write_state" id="@eZs~I(SS/:jD496}g@*"><value name="LED"><block type="led_pin" id="(qbN4yE{@?e;ClO[#jz6"><field name="LED">LED3</field></block></value><value name="VALUE"><block type="code_pin" id="bizQ^Ka}3DZRPxWw,0j$"><field name="CODE_PIN">HIGH</field></block></value><next><block type="flow_delay_micro" id="-M=T~=Td6N9}!+hC;0]w"><value name="DELAY_MICRO"><block type="math_number" id="]fZ#|4D9|QJ4PEuFZs[t"><field name="NUM">10</field></block></value><next><block type="led_write_state" id="C%X#}aI^]Ta^@KcET+;4"><value name="LED"><block type="led_pin" id="MUPm9sh#.CL84)SL.1;!"><field name="LED">LED3</field></block></value><value name="VALUE"><block type="code_pin" id="2f1)Vqr@ka]N!?t(^wxZ"><field name="CODE_PIN">LOW</field></block></value><next><block type="variables_set" id="[qW|t_GpnW%[y%5AaYUg"><field name="VAR" id="UrX!`o6_?c0KL{pT_~F+">Verstrichene Zeit</field><value name="VALUE"><block type="code_pin" id="H#gT/;^m5CrQnF{WR+;7"><field name="CODE_PIN">pulseIn(16, HIGH)</field></block></value><next><block type="variables_set" id="vFnXw[RWuqq].BUHDP8F"><field name="VAR" id="_7ye.we37|x%yj+NX6/w">Distanz in cm</field><value name="VALUE"><block type="code_pin" id="Qc3n[]3qr@Uy9.DJ`)N_"><field name="CODE_PIN">(Verstrichene_Zeit*0.0343)/2</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></statement><value name="RETURN"><block type="variables_get" id=")r}C!FTab-Y:c^j2$u!#"><field name="VAR" id="_7ye.we37|x%yj+NX6/w">Distanz in cm</field></block></value></block></xml>
Challenge erweitert:
In diesen Sketch haben wir noch einen Spezialeffekt eingebaut, welcher als Begrüssungslicht einen Farbverlauf zeigt. Dieser Effekt spielt genau dann ab, wenn der Dimmeffekt bei 99% Helligkeit angelangt ist. Das ist wichtig, denn der Farbeffekt soll ja nur einmal abspielen.
Versuche den eingebauten Farbeffekt zu verstehen und entwerfe eigene Ideen für weitere Lichtanimationen!
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="Fgi(boC*F5V:]r|tcnW,">Distanz in cm</variable><variable id=".+5,G0vF7MTEDK;lC@OM">Helligkeit</variable><variable id="3Ifa`_AMo.Xe7WP#Q7i1">Farbe</variable><variable id="w#g|TWs[|tK%g)vcs!n5">Verstrichene Zeit</variable></variables><block type="basic_comment" id="H~UW;?gR9HL56l!+P|SL" x="-131" y="-123"><field name="COMMENT">Schranktür Challenge mit Dimmer und Spezialeffekt</field></block><block type="set_neo_pixel" id="!Om9r{B%q#Ax%A]Do=O0" x="-131" y="-37"><value name="NUM_LEDS"><block type="math_number" id="sGg3N3FKmd)8(6;uEI{*"><field name="NUM">16</field></block></value><value name="BRIGHTNESS"><block type="math_number" id="W2KAj#}-gE`P}9v*v)3B"><field name="NUM">100</field></block></value><value name="OUTTURN"><block type="led_pin" id="9-MqZA.)f?Uo,GG(]b7X"><field name="LED">LED1</field></block></value></block><block type="basic_comment" id="|.$x+yKiz`j-,~[?eRLs" x="-700" y="32"><field name="COMMENT">Nicht löschen, dies ist die Ultraschallsensor Funktion</field></block><block type="basic_main_loop" id="9~210UV)!{|GniQxFn|[" deletable="false" x="-131" y="37"><value name="BLINK"><block type="basic_blinkcode" id="u@6%knhMhK2g(1JYw[10"><field name="SHORT">1</field><field name="LONG">1</field></block></value><statement name="CODE"><block type="logic_if" id="=}ykQxHO}QTNpu]oo?/:"><mutation xmlns="http://www.w3.org/1999/xhtml" else="1"></mutation><value name="IF0"><block type="logic_compare" id="6(YiA9nyDNW^skN?3nvD"><field name="OP">GT</field><value name="A"><block type="procedures_callreturn" id="rsV|bayB4USpXT9IsJ/l"><mutation name="Gemessene Distanz in cm"></mutation></block></value><value name="B"><block type="math_number" id="Pjy`]qRq$AeD;sCJ9*YZ"><field name="NUM">30</field></block></value></block></value><statement name="DO0"><block type="variables_set" id="(B`XCcuLPN%yoLx{2gJ3"><field name="VAR" id=".+5,G0vF7MTEDK;lC@OM">Helligkeit</field><value name="VALUE"><block type="math_constrain" id="-6od%)5(mWVqJ(;lnm%W"><value name="VALUE"><block type="math_arithmetic" id="5uEUZ!mtF%(TC%7+0+bq"><field name="OP">ADD</field><value name="A"><block type="variables_get" id="Y~:62g,-,9GR^-%=`LRS"><field name="VAR" id=".+5,G0vF7MTEDK;lC@OM">Helligkeit</field></block></value><value name="B"><block type="math_number" id="XbA*+td!1{sp!RB)f-.c"><field name="NUM">0.5</field></block></value></block></value><value name="MIN"><block type="math_number" id="Ma]g9jwSC4)=%eJ2~a7m"><field name="NUM">0</field></block></value><value name="MAX"><block type="math_number" id="GUU)P5@*8~$wT*j#c]jF"><field name="NUM">100</field></block></value></block></value><next><block type="logic_if" id="jqKac6Ov68n/b,.Tsi1J"><value name="IF0"><block type="logic_compare" id="BOt=cb7Ns^Rnyu`{C((}"><field name="OP">EQ</field><value name="A"><block type="variables_get" id="RjoGCDH{^147kuL].d/X"><field name="VAR" id=".+5,G0vF7MTEDK;lC@OM">Helligkeit</field></block></value><value name="B"><block type="math_number" id="acC3uh;6z/~vAsQZXH-Q"><field name="NUM">99</field></block></value></block></value><statement name="DO0"><block type="flow_for" id="!`QbhUD_ZMpNWcb|Y4sM"><field name="VAR" id="3Ifa`_AMo.Xe7WP#Q7i1">Farbe</field><value name="FROM"><block type="math_number" id="j?izj^I=6YGjI5pFqBtp"><field name="NUM">40</field></block></value><value name="TO"><block type="math_number" id="qPB1/=nlz]wT;{sWn0{)"><field name="NUM">400</field></block></value><value name="BY"><block type="math_number" id="son~xbyX=Gq=PS/r,CPI"><field name="NUM">1</field></block></value><statement name="DO"><block type="set_pixel_color" id="Q_hzQkV==B2!fbgAhL4d"><field name="MODE">MODE1</field><value name="FROM"><block type="math_number" id="uiH827OO$]`^CCsjd}kZ"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number" id="cRF5-a3hNHd[ZZ_)yciB"><field name="NUM">16</field></block></value><value name="H"><block type="variables_get" id="pp%H_wP/x-x0731]Um9e"><field name="VAR" id="3Ifa`_AMo.Xe7WP#Q7i1">Farbe</field></block></value><value name="S"><block type="math_number" id="+wCW;%68NXSrUOn@U$Es"><field name="NUM">70</field></block></value><value name="B"><block type="math_number" id="~335k/,LVCZU.dnC_C:/"><field name="NUM">100</field></block></value><next><block type="flow_delay" id="UCy-pEU^+T4d=-)W(D2^"><value name="DELAY"><block type="math_number" id="BDeny~l?l3BIbL}vPNpJ"><field name="NUM">2</field></block></value></block></next></block></statement></block></statement></block></next></block></statement><statement name="ELSE"><block type="variables_set" id="~`HMP%.3pv[e{if?IFGz"><field name="VAR" id=".+5,G0vF7MTEDK;lC@OM">Helligkeit</field><value name="VALUE"><block type="math_constrain" id="kP;PB*;U@dQi*wQ9|dut"><value name="VALUE"><block type="math_arithmetic" id="#aFkbTMj0J,;#tq{!xnE"><field name="OP">MINUS</field><value name="A"><block type="variables_get" id="gchg#BCt|~2Dq0g]/(eK"><field name="VAR" id=".+5,G0vF7MTEDK;lC@OM">Helligkeit</field></block></value><value name="B"><block type="math_number" id="210q.B7i9KBvfR-Q-/xN"><field name="NUM">1</field></block></value></block></value><value name="MIN"><block type="math_number" id="V;_p+X69UA/3TF;H]ADC"><field name="NUM">0</field></block></value><value name="MAX"><block type="math_number" id="Yfj|6kjv?Ew#7.KUps8e"><field name="NUM">100</field></block></value></block></value></block></statement><next><block type="set_pixel_color" id=",q%~kDEJ-i39DEs4U,!y"><field name="MODE">MODE1</field><value name="FROM"><block type="math_number" id="0;kZ.@whgu3/7Uk%_Y(V"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number" id="seWvF~|!zu1EaCd5;])U"><field name="NUM">16</field></block></value><value name="H"><block type="math_number" id="{q+:s-7Yu180O;X(dAZV"><field name="NUM">40</field></block></value><value name="S"><block type="math_number" id="0h5?qRETqCQ=PdMoexV`"><field name="NUM">70</field></block></value><value name="B"><block type="variables_get" id="-Ebhz!v,5eC/Uk?YyF41"><field name="VAR" id=".+5,G0vF7MTEDK;lC@OM">Helligkeit</field></block></value><next><block type="flow_delay" id="Ii=hQz/#JRo|H!7~XF]P"><value name="DELAY"><block type="math_number" id="$e/=p!4MT1Zm1OM5KK#V"><field name="NUM">10</field></block></value></block></next></block></next></block></statement></block><block type="procedures_defreturn" id="VnG.[Xi?K@xVOSmR%A:Q" collapsed="true" x="-698" y="84"><field name="NAME">Gemessene Distanz in cm</field><statement name="STACK"><block type="led_write_state" id="(YnUm|J,9fsc(p4r9s;7"><value name="LED"><block type="led_pin" id="H.T)=mm`Ifwv2Fhc|S2f"><field name="LED">LED3</field></block></value><value name="VALUE"><block type="code_pin" id="2?t[*AxO#`+[63!Kbv|4"><field name="CODE_PIN">LOW</field></block></value><next><block type="flow_delay_micro" id="wg)XFQj(bZQ@7;s8Xn)g"><value name="DELAY_MICRO"><block type="math_number" id="+-ylq#`F5bV2s=I1tqw5"><field name="NUM">2</field></block></value><next><block type="led_write_state" id="^{tG^[d%-ztHVl2chmz3"><value name="LED"><block type="led_pin" id="v*lb+hhl[Wi(7pV0Rh2Y"><field name="LED">LED3</field></block></value><value name="VALUE"><block type="code_pin" id="W@AYsU^fM(0P#-M5(rD5"><field name="CODE_PIN">HIGH</field></block></value><next><block type="flow_delay_micro" id="b1cIi4)J^l_l*FFQ9YDW"><value name="DELAY_MICRO"><block type="math_number" id=";%*_lC[QmT=aFvU2dBmT"><field name="NUM">10</field></block></value><next><block type="led_write_state" id=")#=atR)n~|WSuN9-h*qS"><value name="LED"><block type="led_pin" id="vt(XIF^r7P4^(:[t9(|Y"><field name="LED">LED3</field></block></value><value name="VALUE"><block type="code_pin" id="mC9fceq(Z!8lgrV}*q#s"><field name="CODE_PIN">LOW</field></block></value><next><block type="variables_set" id="abkprn]D|R;FJkV?c1X%"><field name="VAR" id="w#g|TWs[|tK%g)vcs!n5">Verstrichene Zeit</field><value name="VALUE"><block type="code_pin" id="^l1C}Yuf?uC!$*grR2(~"><field name="CODE_PIN">pulseIn(16, HIGH)</field></block></value><next><block type="flow_delay" id="^~$p)C+|`cXjw=]|)4vk"><value name="DELAY"><block type="math_number" id="e`),5T9$86+YFbpttWJ4"><field name="NUM">5</field></block></value><next><block type="variables_set" id="%KSHJ,gWN(m1+Bf15WL-"><field name="VAR" id="Fgi(boC*F5V:]r|tcnW,">Distanz in cm</field><value name="VALUE"><block type="math_arithmetic" id="H!$n-us!:]A80ihl_Z)M"><field name="OP">MULTIPLY</field><value name="A"><block type="variables_get" id="5jMKhuU|jo^bbm)GwQ7-"><field name="VAR" id="w#g|TWs[|tK%g)vcs!n5">Verstrichene Zeit</field></block></value><value name="B"><block type="math_number" id="eWh9Q^v9;dBK`FlU1YC]"><field name="NUM">0.0175</field></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement><value name="RETURN"><block type="variables_get" id="^0,i^h8Sw0}Qz*WLV`X{"><field name="VAR" id="Fgi(boC*F5V:]r|tcnW,">Distanz in cm</field></block></value></block><block type="basic_comment" id="$A;i{fYI`1W8|JTfOrxs" x="356" y="202"><field name="COMMENT">Bei Helligkeit 99% spielt dieser Effekt ab. Bei Helligkeit 100% bleibt das Licht konstant eingeschaltet.</field></block></xml>
Anforderung:
✓ Einfach
✓ Bauen ohne Werkstatt
Thema:
> Licht
> Lichteffekte entwerfen und optimieren
Werkzeug:
> Lötstation
> Klebband
Material:
> Controller: pglu.ch/shop > Mikrocontroller KOMFORT mit BASIS
> Neopixel MATRIX oder Stripe: pglu.ch/shop > Bausatz > Neopixel
Anleitungen:
> Neopixel programmieren: pglu.ch > Coding > Neopixel
3D-Modell:
> Hier anschauen
Videos:
> Vimeo: pglu.ch > Coding > Neopixel
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
Arduino Uno:
> Diese Challenge mit dem Arduino Uno