Skip to content

Commit

Permalink
added sound when dot reach either end of a board
Browse files Browse the repository at this point in the history
  • Loading branch information
designcastle committed Nov 20, 2023
1 parent 30119be commit 6eed423
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion main.blocks
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="syq^x+q$$W$H{[(XIZ3j">x</variable><variable id="xdjS!+$QdrmGP{H5e;;I">counter</variable></variables><comment id="27R(4Je={G+)%W[NtyE," data="0" x="54" y="497" h="120" w="200">Initialize variables</comment></xml>
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="=E)!+LFUx-03Zbny@H-#">x</variable><variable id="R)UD(1MeI7DBp/MK!mIy">counter</variable></variables><comment id="true" minimized="true" data="0" x="985" y="0" h="120" w="480">Simple code developed with use of chatGPT 3.5
Tilt board left or right and use A button to check how many times dot touched the edge on left or right side
Initialize variables</comment><block type="pxt-on-start" id="R)f/@aHDST{f@zjE]n!M" x="0" y="0"><statement name="HANDLER"><block type="variables_set" id="H6dM6:E?c_-ly(k#MP|B"><field name="VAR" id="=E)!+LFUx-03Zbny@H-#">x</field><comment pinned="false" h="80" w="160">X-coordinate for the center of the board</comment><value name="VALUE"><shadow type="math_number" id="s,E=n+508;D=:BW)*fiJ"><field name="NUM">2</field></shadow></value><next><block type="device_show_leds" id="%}}iHR8_+e?2d4e8P+;L"><field name="LEDS">`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`</field><comment pinned="false" h="80" w="160">Display a single red dot in the center of the board</comment></block></next></block></statement></block><block type="device_button_event" id="M0t`:6;4qPLv_p=RdXun" x="287" y="0"><field name="NAME">Button.A</field><comment pinned="false" h="80" w="160">Function to display total count when A button is pressed</comment><statement name="HANDLER"><block type="device_show_number" id="baYDwJtLVE#RhY;,=!G|"><comment pinned="false" h="80" w="160">Display the total count</comment><value name="number"><block type="variables_get" id="fdEA+IVhQUjjpQK3#8%O"><field name="VAR" id="R)UD(1MeI7DBp/MK!mIy">counter</field></block></value></block></statement></block><block type="device_gesture_event" id="!RM:-wO)9@C,?0/z5~vJ" x="654" y="0"><field name="NAME">Gesture.TiltLeft</field><comment pinned="false" h="80" w="160">Function to handle dot movement based on tilt</comment><data>0</data><statement name="HANDLER"><block type="controls_if" id="WZSmS5!}e6TOHHi.WaCO"><mutation else="1"></mutation><value name="IF0"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="logic_compare" id="W]]9lz53vAcQHFAmT9/K"><field name="OP">GT</field><value name="A"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="variables_get" id="9}?eBH|S;H;+__4e.V*p"><field name="VAR" id="=E)!+LFUx-03Zbny@H-#">x</field></block></value><value name="B"><shadow type="math_number" id="z41x)Yj[RwGw4;)s;o8%"><field name="NUM">0</field></shadow></value></block></value><statement name="DO0"><block type="variables_change" id="L,9;8*jeXPF!5`O3y.7s"><field name="VAR" id="=E)!+LFUx-03Zbny@H-#">x</field><comment pinned="false" h="80" w="160">Move the dot left if not already at the left edge</comment><value name="VALUE"><shadow type="math_number" id="R1c(%sm%_U;+sP==^TdR"><field name="NUM">-1</field></shadow></value><next><block type="device_clear_display" id=",631$%^e:[L`DXlAe)Y["><next><block type="device_plot" id="ZR~X)?bO{TU;E{G=1`/q"><value name="x"><shadow type="math_number_minmax"><mutation min="0" max="4"></mutation><field name="SLIDER">0</field></shadow><block type="variables_get" id="B%Z3T{24,9y6bhv`m%19"><field name="VAR" id="=E)!+LFUx-03Zbny@H-#">x</field></block></value><value name="y"><shadow type="math_number_minmax" id="sljw?Af6m4)ntKjf{jPC"><mutation min="0" max="4" label="Number" precision="0"></mutation><field name="SLIDER">2</field></shadow></value><next><block type="controls_if" id="?UB^md]RK{zFvf)mK$Vf"><value name="IF0"><shadow type="logic_boolean" id="VOnLhcdcCRF~R^BWH(qv" disabled="true"><field name="BOOL">TRUE</field></shadow><block type="logic_compare" id="[49aLC%N5pdG6Ga1]s]l"><field name="OP">LTE</field><value name="A"><shadow type="math_number" id="X!b8$!zD0b:?]kt:8M?V" disabled="true"><field name="NUM">0</field></shadow><block type="variables_get" id="z$Lc{;Lavo!RXJmUHc^7"><field name="VAR" id="=E)!+LFUx-03Zbny@H-#">x</field></block></value><value name="B"><shadow type="math_number" id="GVT|uMKn;N{xyf{0uwyi"><field name="NUM">0</field></shadow></value></block></value><statement name="DO0"><block type="music_playable_play" id="66Ob-t|q1$Nq==}fYp9T"><field name="playbackMode">music.PlaybackMode.UntilDone</field><value name="toPlay"><shadow type="music_tone_playable" id="MCn6hMAkC[O[k1JcuiN~"><value name="note"><shadow type="device_note" id="LII97iWZ7JWp/zMXlE^e"><field name="name">784</field></shadow></value><value name="duration"><shadow type="device_beat" id="xTWfC%2G$#dB;}ueE4vw"><field name="fraction">BeatFraction.Quarter</field></shadow></value></shadow></value></block></statement></block></next></block></next></block></next></block></statement><statement name="ELSE"><block type="variables_change" id="SAiePjIh]5#H(p2DiJr$"><field name="VAR" id="R)UD(1MeI7DBp/MK!mIy">counter</field><comment pinned="false" h="80" w="160">Increment counter when dot reaches the left edge</comment><value name="VALUE"><shadow type="math_number" id="*^:;WV~z75).4[#6.T04"><field name="NUM">1</field></shadow></value></block></statement></block></statement></block><block type="device_gesture_event" id="@hW3HAdNX8j#JlxeeP:8" x="6" y="373"><field name="NAME">Gesture.TiltRight</field><statement name="HANDLER"><block type="controls_if" id="=q773}*A/H9]#T@MXf4x"><mutation else="1"></mutation><value name="IF0"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="logic_compare" id=";}^.+fhT_-Yt[x?@,vjp"><field name="OP">LT</field><value name="A"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="variables_get" id="h`0c[-W*2ul_L=5QYcxV"><field name="VAR" id="=E)!+LFUx-03Zbny@H-#">x</field></block></value><value name="B"><shadow type="math_number" id="O2Oe~twuh76eN7{eNQZm"><field name="NUM">4</field></shadow></value></block></value><statement name="DO0"><block type="variables_change" id="L,A%l~BJ5Q]*qG#iq+/D"><field name="VAR" id="=E)!+LFUx-03Zbny@H-#">x</field><comment pinned="false" h="80" w="160">Move the dot right if not already at the right edge</comment><value name="VALUE"><shadow type="math_number" id="Y466pzR/6*GfN!FJouc;"><field name="NUM">1</field></shadow></value><next><block type="device_clear_display" id="LGa%ER2n(Af-OKV,*n9#"><next><block type="device_plot" id="|.)(@]z:yx2p!{=v,*Iv"><value name="x"><shadow type="math_number_minmax"><mutation min="0" max="4"></mutation><field name="SLIDER">0</field></shadow><block type="variables_get" id="-h@;BWF/*{1wep3RB}T}"><field name="VAR" id="=E)!+LFUx-03Zbny@H-#">x</field></block></value><value name="y"><shadow type="math_number_minmax" id="Ef/Qr%TOKs$NjQWJ7,n`"><mutation min="0" max="4" label="Number" precision="0"></mutation><field name="SLIDER">2</field></shadow></value><next><block type="controls_if" id="Z;]VCoZH$Ufl!}9nfHko"><value name="IF0"><shadow type="logic_boolean" disabled="true"><field name="BOOL">TRUE</field></shadow><block type="logic_compare" id="Ws7:i(l6x$k6t8,E0nna"><field name="OP">GTE</field><value name="A"><shadow type="math_number" disabled="true"><field name="NUM">0</field></shadow><block type="variables_get" id="C7IOeF,q7c?mqOl8;hjp"><field name="VAR" id="=E)!+LFUx-03Zbny@H-#">x</field></block></value><value name="B"><shadow type="math_number" id="(N|zJVl(Jop`u2L}[YCD"><field name="NUM">4</field></shadow></value></block></value><statement name="DO0"><block type="music_playable_play" id="fm!zHk#]FY@8p,G$c2~W"><field name="playbackMode">music.PlaybackMode.UntilDone</field><value name="toPlay"><shadow type="music_tone_playable" id="2xa(Eb3Xer%hA{)9xP1{"><value name="note"><shadow type="device_note" id="ZG8=Yi#W!*UYV-EvIEz%"><field name="name">784</field></shadow></value><value name="duration"><shadow type="device_beat" id="`zNEjt7)y:]KbPX-;#mi"><field name="fraction">BeatFraction.Quarter</field></shadow></value></shadow></value></block></statement></block></next></block></next></block></next></block></statement><statement name="ELSE"><block type="variables_change" id="46myTa#.$:uhW:f;i{!7"><field name="VAR" id="R)UD(1MeI7DBp/MK!mIy">counter</field><comment pinned="false" h="80" w="160">Increment counter when dot reaches the right edge</comment><value name="VALUE"><shadow type="math_number" id="QiV}dP]SQ+bK}wzI(iSQ"><field name="NUM">1</field></shadow></value></block></statement></block></statement></block></xml>
8 changes: 8 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* Simple code developed with use of chatGPT 3.5
*
* Tilt board left or right and use A button to check how many times dot touched the edge on left or right side
*
* Initialize variables
*/
// Function to handle dot movement based on tilt
Expand All @@ -10,6 +12,9 @@ input.onGesture(Gesture.TiltLeft, function () {
x += -1
basic.clearScreen()
led.plot(x, 2)
if (x <= 0) {
music.play(music.tonePlayable(784, music.beat(BeatFraction.Quarter)), music.PlaybackMode.UntilDone)
}
} else {
// Increment counter when dot reaches the left edge
counter += 1
Expand All @@ -21,6 +26,9 @@ input.onGesture(Gesture.TiltRight, function () {
x += 1
basic.clearScreen()
led.plot(x, 2)
if (x >= 4) {
music.play(music.tonePlayable(784, music.beat(BeatFraction.Quarter)), music.PlaybackMode.UntilDone)
}
} else {
// Increment counter when dot reaches the right edge
counter += 1
Expand Down
2 changes: 1 addition & 1 deletion pxt.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
"supportedTargets": [
"microbit"
],
"preferredEditor": "tsprj"
"preferredEditor": "blocksprj"
}

0 comments on commit 6eed423

Please sign in to comment.