pxt-microbit 7.0.19 → 7.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/built/block-tests.js +1 -1
- package/built/editor.js +24 -4
- package/built/target-strings.json +1 -1
- package/built/target.js +1 -1
- package/built/target.json +1 -1
- package/built/targetlight.json +1 -1
- package/docs/extensions/extension-gallery.md +12 -8
- package/docs/projects/analog-pin-tester.md +1 -1
- package/docs/projects/banana-keyboard/code.md +25 -25
- package/docs/projects/banana-keyboard/make.md +1 -1
- package/docs/projects/crashy-bird.md +12 -12
- package/docs/projects/fireflies.md +3 -3
- package/docs/projects/guitar/accelerometer.md +5 -5
- package/docs/projects/guitar/displaybuttons.md +7 -7
- package/docs/projects/guitar/lightsensor.md +4 -4
- package/docs/projects/guitar/pinpress.md +12 -12
- package/docs/projects/hack-your-headphones/code.md +19 -19
- package/docs/projects/hot-or-cold/beacon.md +1 -1
- package/docs/projects/hot-or-cold/multi-beacons.md +2 -2
- package/docs/projects/hot-or-cold/seekers.md +2 -2
- package/docs/projects/hot-or-cold.md +3 -3
- package/docs/projects/inchworm/code.md +5 -5
- package/docs/projects/inchworm/connect.md +1 -1
- package/docs/projects/infection.md +175 -175
- package/docs/projects/karel.md +37 -37
- package/docs/projects/light-monster/code.md +1 -1
- package/docs/projects/light-monster/connect.md +2 -2
- package/docs/projects/magic-button-trick.md +13 -13
- package/docs/projects/micro-coin.md +3 -3
- package/docs/projects/milk-carton-robot/code.md +3 -3
- package/docs/projects/milk-carton-robot/connect.md +2 -2
- package/docs/projects/milky-monster/code.md +3 -3
- package/docs/projects/milky-monster/connect.md +2 -2
- package/docs/projects/mood-radio.md +4 -4
- package/docs/projects/plant-watering/code.md +1 -1
- package/docs/projects/railway-crossing.md +5 -5
- package/docs/projects/rc-car/code.md +2 -2
- package/docs/projects/rc-car/connect.md +6 -6
- package/docs/projects/reaction-time/code.md +15 -15
- package/docs/projects/salute.md +5 -5
- package/docs/projects/servo-calibrator.md +3 -3
- package/docs/projects/soil-moisture/code.md +3 -3
- package/docs/projects/soil-moisture/connect.md +2 -5
- package/docs/projects/spy/coin-flipper.md +4 -4
- package/docs/projects/spy/rock-paper-scissors.md +3 -3
- package/docs/projects/states-of-matter/code.md +15 -15
- package/docs/projects/tele-potato.md +6 -6
- package/docs/projects/telegraph/code.md +7 -7
- package/docs/projects/timing-gates.md +11 -11
- package/docs/projects/turtle-scanner.md +1 -1
- package/docs/projects/turtle-spiral.md +1 -1
- package/docs/projects/voting-machine.md +4 -4
- package/docs/projects/wallet/code.md +2 -2
- package/docs/projects/watch/code.md +11 -11
- package/docs/projects/watch/digital-watch.md +37 -37
- package/docs/projects/watch/timer.md +9 -9
- package/docs/teachertool.md +178 -0
- package/package.json +2 -2
- package/targetconfig.json +2 -0
package/built/targetlight.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"microbit","nickname":"microbit","name":"makecode.microbit.org","title":"Microsoft MakeCode for micro:bit","description":"A Blocks / JavaScript code editor for the micro:bit powered by Microsoft MakeCode.","corepkg":"core","cloud":{"workspace":false,"packages":true,"sharing":true,"thumbnails":true,"publishing":true,"importing":true,"showBadges":false,"preferredPackages":["Microsoft/pxt-neopixel"],"githubPackages":true,"cloudProviders":{"github":{"id":"github","name":"GitHub","icon":"./static/providers/github-mark.png","identity":false,"order":3},"microsoft":{"id":"microsoft","name":"Microsoft","icon":"./static/providers/microsoft-logo.svg","identity":true,"redirect":true,"order":1},"google":{"id":"google","name":"Google","icon":"./static/providers/google-logo.svg","identity":true,"redirect":true,"order":2},"clever":{"id":"clever","name":"Clever","icon":"./static/providers/clever-logo.png","identity":true,"redirect":true,"order":3}}},"compile":{"isNative":false,"hasHex":true,"deployDrives":"(MICROBIT|MBED)","driveName":"MICROBIT","hexMimeType":"application/x-microbit-hex","openocdScript":"source [find interface/cmsis-dap.cfg]; source [find target/nrf51.cfg]","flashUsableEnd":242688,"flashEnd":242688,"flashCodeAlign":1024,"floatingPoint":true,"taggedInts":true,"utf8":false,"gc":true,"imageRefTag":9,"shimRenames":{"sendBufferAsm":"light::sendWS2812Buffer"},"patches":{"0.0.0 - 1.0.0":[{"type":"package","map":{"microbit":"core","microbit-bluetooth":"bluetooth","microbit-radio":"radio","microbit-devices":"devices","microbit-led":"","microbit-music":"","microbit-game":"","microbit-pins":"","microbit-serial":""}},{"type":"missingPackage","map":{"radio\\s*\\.":"radio","bluetooth\\s*\\.":"bluetooth","devices\\s*\\.":"devices"}},{"type":"api","map":{"bluetooth\\s*\\.\\s*uartRead\\s*\\((.*?)\\)":"bluetooth.uartReadUntil($1)","bluetooth\\s*\\.\\s*uartWrite\\s*\\((.*?)\\)":"bluetooth.uartWriteUntil($1)","input\\s*\\.\\s*calibrate\\s*\\(":"input.calibrateCompass(","radio\\s*\\.\\s*onDataPacketReceived\\(\\s*\\(\\{\\s*receivedNumber\\s*\\}\\)\\s*=>\\s*\\{":"radio.onReceivedNumber(function (receivedNumber) {","radio\\s*\\.\\s*onDataPacketReceived\\(\\s*\\(\\{\\s*receivedString: name, receivedNumber: value\\s*\\}\\)\\s*=>\\s*\\{":"radio.onReceivedValue(function (name, value) {","radio\\s*\\.\\s*onDataPacketReceived\\(\\s*\\(\\{\\s*receivedString\\s*\\}\\)\\s*=>\\s*\\{":"radio.onReceivedString(function (receivedString) {","Math\\s*\\.\\s*random\\s*\\(":"Math.randomRange(0, "}},{"type":"blockId","map":{"device_get_acceleration":"device_acceleration"}},{"type":"blockValue","map":{"device_print_message.message":"text"}}],"0.0.0 - 1.4.12":[{"type":"api","map":{"DisplayMode\\s*\\.\\s*BackAndWhite":"DisplayMode.BlackAndWhite"}}],"0.0.0 - 3.1.10":[{"type":"package","map":{"pxt-microbit-v2-extension":"microphone"}}],"0.0.0 - 3.0.18":[{"type":"missingPackage","map":{".*":"microphone"}}]},"hidSelectors":[{"usagePage":"0xFF00","usageId":"0x0001","vid":"0x0d28","pid":"0x0204"}],"webUSB":true,"useNewFunctions":true,"nativeType":"thumb","switches":{},"jsRefCounting":false,"noSourceInFlash":true},"compileService":{"yottaTarget":"bbc-microbit-classic-gcc@https://github.com/lancaster-university/yotta-target-bbc-microbit-classic-gcc","yottaCorePackage":"microbit","githubCorePackage":"lancaster-university/microbit","gittag":"v2.2.0-rc6","serviceId":"microbit","dockerImage":"pext/yotta:gcc5","yottaBinary":"pxt-microbit-app-combined.hex"},"multiVariants":["mbdal","mbcodal"],"alwaysMultiVariant":true,"variants":{"mbdal":{"compile":{},"compileService":{}},"mbcodal":{"compile":{"flashCodeAlign":4096,"flashUsableEnd":487424,"flashEnd":524288},"compileService":{"buildEngine":"codal","codalTarget":{"name":"codal-microbit-v2","url":"https://github.com/lancaster-university/codal-microbit-v2","branch":"v0.2.67","type":"git"},"codalBinary":"MICROBIT","githubCorePackage":"lancaster-university/microbit-v2-samples","gittag":"v0.2.13","serviceId":"mbcodal2","dockerImage":"pext/yotta:latest","yottaConfigCompatibility":true}}},"runtime":{"mathBlocks":true,"loopsBlocks":true,"logicBlocks":true,"variablesBlocks":true,"textBlocks":true,"listsBlocks":true,"functionBlocks":true,"breakBlock":true,"continueBlock":true,"functionsOptions":{"useNewFunctions":true,"extraFunctionEditorTypes":[{"typeName":"game.LedSprite","label":"LedSprite","icon":"send","defaultName":"sprite"},{"typeName":"Image","label":"Image","icon":"image outline","defaultName":"image"}]},"onStartColor":"#1E90FF","onStartNamespace":"basic","onStartWeight":54},"simulator":{"autoRun":true,"streams":false,"aspectRatio":1.22,"parts":true,"partsAspectRatio":0.69,"messageSimulators":{"jacdac":{"url":"https://microsoft.github.io/jacdac-docs/tools/makecode-sim?webusb=0&parentOrigin=$PARENT_ORIGIN$","localHostUrl":"http://localhost:8000/tools/makecode-sim?webusb=0&parentOrigin=$PARENT_ORIGIN$","aspectRatio":1.22,"permanent":true},"robot":{"url":"https://microsoft.github.io/microbit-robot/?parentOrigin=$PARENT_ORIGIN$","localHostUrl":"http://localhost:3000/microbit-robot/?parentOrigin=$PARENT_ORIGIN$","aspectRatio":1.22,"permanent":true}},"boardDefinition":{"visual":"microbit","gpioPinBlocks":[["P0"],["P1"],["P2"],["P3"],["P4","P5","P6","P7"],["P8","P9","P10","P11","P12"],["P16"]],"gpioPinMap":{"P0":"P0","P1":"P1","P2":"P2","P3":"P3","P4":"P4","P5":"P5","P6":"P6","P7":"P7","P8":"P8","P9":"P9","P10":"P10","P11":"P11","P12":"P12","P13":"P13","P14":"P14","P15":"P15","P16":"P16","P19":"P19","P20":"P20"},"spiPins":{"MOSI":"P15","MISO":"P14","SCK":"P13"},"i2cPins":{"SDA":"P20","SCL":"P19"},"analogInPins":["P0","P1","P2","P3","P10"],"groundPins":["GND"],"threeVoltPins":["+3v3"],"attachPowerOnRight":true,"onboardComponents":["accelerometer","buttonpair","ledmatrix","speaker","bluetooth","thermometer","compass","builtinspeaker","microphone","logotouch","flashlog","v2"],"pinStyles":{"P0":"croc","P1":"croc","P2":"croc","GND":"croc","+3v3":"croc"},"marginWhenBreadboarding":[0,0,80,0]}},"serial":{"nameFilter":"^(mbed Serial Port|DAPLink CMSIS-DAP)","log":true,"useEditor":true,"editorTheme":{"graphBackground":"#d9d9d9","lineColors":["#6633cc","#2C7485","#3454D1","#EF767A","#F46197","#107C10"]},"vendorId":"0x0d28","productId":"0x0204","rawHID":true},"queryVariants":{"hidemenu":{"appTheme":{"hideMenuBar":true}},"androidapp":{"compile":{"webUSB":false},"appTheme":{"disableBlobObjectDownload":true}},"skillsMap=1":{"appTheme":{"hideReplaceMyCode":false}},"teachertool=1":{"appTheme":{"hideMenuBar":true,"workspaceSearch":true}}},"uploadDocs":true,"versions":{"branch":"v7.0.
|
|
1
|
+
{"id":"microbit","nickname":"microbit","name":"makecode.microbit.org","title":"Microsoft MakeCode for micro:bit","description":"A Blocks / JavaScript code editor for the micro:bit powered by Microsoft MakeCode.","corepkg":"core","cloud":{"workspace":false,"packages":true,"sharing":true,"thumbnails":true,"publishing":true,"importing":true,"showBadges":false,"preferredPackages":["Microsoft/pxt-neopixel"],"githubPackages":true,"cloudProviders":{"github":{"id":"github","name":"GitHub","icon":"./static/providers/github-mark.png","identity":false,"order":3},"microsoft":{"id":"microsoft","name":"Microsoft","icon":"./static/providers/microsoft-logo.svg","identity":true,"redirect":true,"order":1},"google":{"id":"google","name":"Google","icon":"./static/providers/google-logo.svg","identity":true,"redirect":true,"order":2},"clever":{"id":"clever","name":"Clever","icon":"./static/providers/clever-logo.png","identity":true,"redirect":true,"order":3}}},"compile":{"isNative":false,"hasHex":true,"deployDrives":"(MICROBIT|MBED)","driveName":"MICROBIT","hexMimeType":"application/x-microbit-hex","openocdScript":"source [find interface/cmsis-dap.cfg]; source [find target/nrf51.cfg]","flashUsableEnd":242688,"flashEnd":242688,"flashCodeAlign":1024,"floatingPoint":true,"taggedInts":true,"utf8":false,"gc":true,"imageRefTag":9,"shimRenames":{"sendBufferAsm":"light::sendWS2812Buffer"},"patches":{"0.0.0 - 1.0.0":[{"type":"package","map":{"microbit":"core","microbit-bluetooth":"bluetooth","microbit-radio":"radio","microbit-devices":"devices","microbit-led":"","microbit-music":"","microbit-game":"","microbit-pins":"","microbit-serial":""}},{"type":"missingPackage","map":{"radio\\s*\\.":"radio","bluetooth\\s*\\.":"bluetooth","devices\\s*\\.":"devices"}},{"type":"api","map":{"bluetooth\\s*\\.\\s*uartRead\\s*\\((.*?)\\)":"bluetooth.uartReadUntil($1)","bluetooth\\s*\\.\\s*uartWrite\\s*\\((.*?)\\)":"bluetooth.uartWriteUntil($1)","input\\s*\\.\\s*calibrate\\s*\\(":"input.calibrateCompass(","radio\\s*\\.\\s*onDataPacketReceived\\(\\s*\\(\\{\\s*receivedNumber\\s*\\}\\)\\s*=>\\s*\\{":"radio.onReceivedNumber(function (receivedNumber) {","radio\\s*\\.\\s*onDataPacketReceived\\(\\s*\\(\\{\\s*receivedString: name, receivedNumber: value\\s*\\}\\)\\s*=>\\s*\\{":"radio.onReceivedValue(function (name, value) {","radio\\s*\\.\\s*onDataPacketReceived\\(\\s*\\(\\{\\s*receivedString\\s*\\}\\)\\s*=>\\s*\\{":"radio.onReceivedString(function (receivedString) {","Math\\s*\\.\\s*random\\s*\\(":"Math.randomRange(0, "}},{"type":"blockId","map":{"device_get_acceleration":"device_acceleration"}},{"type":"blockValue","map":{"device_print_message.message":"text"}}],"0.0.0 - 1.4.12":[{"type":"api","map":{"DisplayMode\\s*\\.\\s*BackAndWhite":"DisplayMode.BlackAndWhite"}}],"0.0.0 - 3.1.10":[{"type":"package","map":{"pxt-microbit-v2-extension":"microphone"}}],"0.0.0 - 3.0.18":[{"type":"missingPackage","map":{".*":"microphone"}}]},"hidSelectors":[{"usagePage":"0xFF00","usageId":"0x0001","vid":"0x0d28","pid":"0x0204"}],"webUSB":true,"useNewFunctions":true,"nativeType":"thumb","switches":{},"jsRefCounting":false,"noSourceInFlash":true},"compileService":{"yottaTarget":"bbc-microbit-classic-gcc@https://github.com/lancaster-university/yotta-target-bbc-microbit-classic-gcc","yottaCorePackage":"microbit","githubCorePackage":"lancaster-university/microbit","gittag":"v2.2.0-rc6","serviceId":"microbit","dockerImage":"pext/yotta:gcc5","yottaBinary":"pxt-microbit-app-combined.hex"},"multiVariants":["mbdal","mbcodal"],"alwaysMultiVariant":true,"variants":{"mbdal":{"compile":{},"compileService":{}},"mbcodal":{"compile":{"flashCodeAlign":4096,"flashUsableEnd":487424,"flashEnd":524288},"compileService":{"buildEngine":"codal","codalTarget":{"name":"codal-microbit-v2","url":"https://github.com/lancaster-university/codal-microbit-v2","branch":"v0.2.67","type":"git"},"codalBinary":"MICROBIT","githubCorePackage":"lancaster-university/microbit-v2-samples","gittag":"v0.2.13","serviceId":"mbcodal2","dockerImage":"pext/yotta:latest","yottaConfigCompatibility":true}}},"runtime":{"mathBlocks":true,"loopsBlocks":true,"logicBlocks":true,"variablesBlocks":true,"textBlocks":true,"listsBlocks":true,"functionBlocks":true,"breakBlock":true,"continueBlock":true,"functionsOptions":{"useNewFunctions":true,"extraFunctionEditorTypes":[{"typeName":"game.LedSprite","label":"LedSprite","icon":"send","defaultName":"sprite"},{"typeName":"Image","label":"Image","icon":"image outline","defaultName":"image"}]},"onStartColor":"#1E90FF","onStartNamespace":"basic","onStartWeight":54},"simulator":{"autoRun":true,"streams":false,"aspectRatio":1.22,"parts":true,"partsAspectRatio":0.69,"messageSimulators":{"jacdac":{"url":"https://microsoft.github.io/jacdac-docs/tools/makecode-sim?webusb=0&parentOrigin=$PARENT_ORIGIN$","localHostUrl":"http://localhost:8000/tools/makecode-sim?webusb=0&parentOrigin=$PARENT_ORIGIN$","aspectRatio":1.22,"permanent":true},"robot":{"url":"https://microsoft.github.io/microbit-robot/?parentOrigin=$PARENT_ORIGIN$","localHostUrl":"http://localhost:3000/microbit-robot/?parentOrigin=$PARENT_ORIGIN$","aspectRatio":1.22,"permanent":true}},"boardDefinition":{"visual":"microbit","gpioPinBlocks":[["P0"],["P1"],["P2"],["P3"],["P4","P5","P6","P7"],["P8","P9","P10","P11","P12"],["P16"]],"gpioPinMap":{"P0":"P0","P1":"P1","P2":"P2","P3":"P3","P4":"P4","P5":"P5","P6":"P6","P7":"P7","P8":"P8","P9":"P9","P10":"P10","P11":"P11","P12":"P12","P13":"P13","P14":"P14","P15":"P15","P16":"P16","P19":"P19","P20":"P20"},"spiPins":{"MOSI":"P15","MISO":"P14","SCK":"P13"},"i2cPins":{"SDA":"P20","SCL":"P19"},"analogInPins":["P0","P1","P2","P3","P10"],"groundPins":["GND"],"threeVoltPins":["+3v3"],"attachPowerOnRight":true,"onboardComponents":["accelerometer","buttonpair","ledmatrix","speaker","bluetooth","thermometer","compass","builtinspeaker","microphone","logotouch","flashlog","v2"],"pinStyles":{"P0":"croc","P1":"croc","P2":"croc","GND":"croc","+3v3":"croc"},"marginWhenBreadboarding":[0,0,80,0]}},"serial":{"nameFilter":"^(mbed Serial Port|DAPLink CMSIS-DAP)","log":true,"useEditor":true,"editorTheme":{"graphBackground":"#d9d9d9","lineColors":["#6633cc","#2C7485","#3454D1","#EF767A","#F46197","#107C10"]},"vendorId":"0x0d28","productId":"0x0204","rawHID":true},"queryVariants":{"hidemenu":{"appTheme":{"hideMenuBar":true}},"androidapp":{"compile":{"webUSB":false},"appTheme":{"disableBlobObjectDownload":true}},"skillsMap=1":{"appTheme":{"hideReplaceMyCode":false}},"teachertool=1":{"appTheme":{"hideMenuBar":true,"workspaceSearch":true}}},"uploadDocs":true,"versions":{"branch":"v7.0.21","tag":"v7.0.21","commits":"https://github.com/microsoft/pxt-microbit/commits/9fd486acda26da2d1a09bc78b3a2e8e5de1b5aa6","target":"7.0.21","pxt":"10.2.11"},"blocksprj":{"id":"blocksprj","config":{"name":"{0} block","dependencies":{"core":"*","radio":"*","microphone":"*"},"description":"","files":["main.blocks","main.ts","README.md"],"additionalFilePaths":[]},"files":{"README.md":"","main.blocks":"<xml xmlns=\"http://www.w3.org/1999/xhtml\">\n <block type=\"pxt-on-start\"></block>\n <block type=\"device_forever\"></block>\n</xml>","main.ts":"\n"}},"tsprj":{"id":"tsprj","config":{"name":"{0} bit","dependencies":{"core":"*","radio":"*","microphone":"*"},"description":"","files":["main.ts","README.md"],"additionalFilePaths":[]},"files":{"README.md":"","main.ts":"basic.showLeds(`\n . . . . .\n . # . # .\n . . . . .\n # . . . #\n . # # # .\n `);"}}}
|
|
@@ -812,6 +812,18 @@ Many extensions are available to work with interface kits, add-on hardware, or o
|
|
|
812
812
|
"name": "TinkerTanker Stepper Motor",
|
|
813
813
|
"url":"/pkg/Tinkertanker/pxt-stepper-motor",
|
|
814
814
|
"cardType": "package"
|
|
815
|
+
}, {
|
|
816
|
+
"name": "ALS Robot Keyboard",
|
|
817
|
+
"url":"/pkg/alsrobot-microbit-makecode-packages/ALSRobotKeyboard",
|
|
818
|
+
"cardType": "package"
|
|
819
|
+
}, {
|
|
820
|
+
"name": "Elecfreaks NeZha",
|
|
821
|
+
"url": "/pkg/elecfreaks/pxt-nezha",
|
|
822
|
+
"cardType": "package"
|
|
823
|
+
}, {
|
|
824
|
+
"name": "Elecfreaks NeZha V2",
|
|
825
|
+
"url": "/pkg/elecfreaks/pxt-nezha2",
|
|
826
|
+
"cardType": "package"
|
|
815
827
|
}]
|
|
816
828
|
```
|
|
817
829
|
|
|
@@ -1079,13 +1091,5 @@ Many extensions are available to work with interface kits, add-on hardware, or o
|
|
|
1079
1091
|
"name": "Proportional Font",
|
|
1080
1092
|
"url":"/pkg/lwchkg/pxt-proportional-font",
|
|
1081
1093
|
"cardType": "package"
|
|
1082
|
-
}, {
|
|
1083
|
-
"name": "ALS Robot Keyboard",
|
|
1084
|
-
"url":"/pkg/alsrobot-microbit-makecode-packages/ALSRobotKeyboard",
|
|
1085
|
-
"cardType": "package"
|
|
1086
|
-
}, {
|
|
1087
|
-
"name": "Elecfreaks NeZha",
|
|
1088
|
-
"url": "/pkg/elecfreaks/pxt-nezha",
|
|
1089
|
-
"cardType": "package"
|
|
1090
1094
|
}]
|
|
1091
1095
|
```
|
|
@@ -7,14 +7,14 @@ Have you ever tried making beat box sounds? Let's try making a beatbox with code
|
|
|
7
7
|
Start by adding a variable to store a musical note. Rename the variable to `sound`. Set the value of the variable to the note block `Middle A` from the **Music** drawer.
|
|
8
8
|
|
|
9
9
|
```blocks
|
|
10
|
-
let sound = music.noteFrequency(Note.A)
|
|
10
|
+
let sound = music.noteFrequency(Note.A)
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
We want to play music when the fruit connected to a pin pressed. So, we register an event handler that executes whenever pin **1** is pressed. Pin **1** is, of course, connected to the banana. Add a ``||input:on pin pressed||`` block from the **Input** drawer.
|
|
14
14
|
|
|
15
15
|
```blocks
|
|
16
|
-
let sound = music.noteFrequency(Note.A)
|
|
17
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
16
|
+
let sound = music.noteFrequency(Note.A)
|
|
17
|
+
input.onPinPressed(TouchPin.P1, function () {
|
|
18
18
|
|
|
19
19
|
})
|
|
20
20
|
```
|
|
@@ -22,28 +22,28 @@ input.onPinPressed(TouchPin.P1, () => {
|
|
|
22
22
|
Now, let's create some notes to play when the banana is pressed. Click on the **Loops** drawer then insert a ``||loops:repeat||`` loop into the ``||input:on pin pressed||`` block. Click on the **Variables** drawer and pull out a ``||variables:change item by||`` block and put it into the loop. Rename the variable to `sound`. Change the value from `1` to `25`. This will increase the variable `sound` from the note frequency of block `Middle A` to `Middle A` plus 25 and so on. Put a ``||variables:set to||`` block for `sound` right after the loop. Set it to `Middle A` in order to reset the sound after a banana press.
|
|
23
23
|
|
|
24
24
|
```blocks
|
|
25
|
-
let sound = music.noteFrequency(Note.A)
|
|
25
|
+
let sound = music.noteFrequency(Note.A)
|
|
26
26
|
|
|
27
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
27
|
+
input.onPinPressed(TouchPin.P1, function () {
|
|
28
28
|
for (let i = 0; i < 4; i++) {
|
|
29
|
-
sound += 25
|
|
29
|
+
sound += 25
|
|
30
30
|
}
|
|
31
|
-
sound = music.noteFrequency(Note.A)
|
|
32
|
-
})
|
|
31
|
+
sound = music.noteFrequency(Note.A)
|
|
32
|
+
})
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
Finally, insert a ``||music:play tone||`` above the ``||variables:change by||``. Pull out the ``sound`` variable block and drop it in the note slot of ``||music:play tone||``. Change the beat fraction from `1` to `1/4`.
|
|
36
36
|
|
|
37
37
|
```blocks
|
|
38
|
-
let sound = music.noteFrequency(Note.A)
|
|
38
|
+
let sound = music.noteFrequency(Note.A)
|
|
39
39
|
|
|
40
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
40
|
+
input.onPinPressed(TouchPin.P1, function () {
|
|
41
41
|
for (let i = 0; i < 4; i++) {
|
|
42
|
-
music.playTone(sound, music.beat(BeatFraction.Quarter))
|
|
43
|
-
sound += 25
|
|
42
|
+
music.playTone(sound, music.beat(BeatFraction.Quarter))
|
|
43
|
+
sound += 25
|
|
44
44
|
}
|
|
45
|
-
sound = music.noteFrequency(Note.A)
|
|
46
|
-
})
|
|
45
|
+
sound = music.noteFrequency(Note.A)
|
|
46
|
+
})
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
Click `|Download|` and try a banana press. Did you hear 4 notes play?
|
|
@@ -55,23 +55,23 @@ Go back to **[Make](/projects/banana-keyboard/make)** and repeat steps 7 and 8 w
|
|
|
55
55
|
Duplicate the ``||input:on pin pressed||`` event handler to make a second one. For the new ``||input:on pin pressed||``, change the pin name to **P2**. In the pin **P2** event, let's have the the frequency in the variable `sound` decrease by 25 instead of having it increase. Change the `25` in the ``||variables:change by||`` block to `-25`. OK, your code now looks like this:
|
|
56
56
|
|
|
57
57
|
```blocks
|
|
58
|
-
let sound = music.noteFrequency(Note.A)
|
|
58
|
+
let sound = music.noteFrequency(Note.A)
|
|
59
59
|
|
|
60
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
60
|
+
input.onPinPressed(TouchPin.P1, function () {
|
|
61
61
|
for (let i = 0; i < 4; i++) {
|
|
62
|
-
music.playTone(sound, music.beat(BeatFraction.Quarter))
|
|
63
|
-
sound += 25
|
|
62
|
+
music.playTone(sound, music.beat(BeatFraction.Quarter))
|
|
63
|
+
sound += 25
|
|
64
64
|
}
|
|
65
|
-
sound = music.noteFrequency(Note.A)
|
|
66
|
-
})
|
|
65
|
+
sound = music.noteFrequency(Note.A)
|
|
66
|
+
})
|
|
67
67
|
|
|
68
|
-
input.onPinPressed(TouchPin.P2, ()
|
|
68
|
+
input.onPinPressed(TouchPin.P2, function () {
|
|
69
69
|
for (let i = 0; i < 4; i++) {
|
|
70
|
-
music.playTone(sound, music.beat(BeatFraction.Quarter))
|
|
71
|
-
sound += -25
|
|
70
|
+
music.playTone(sound, music.beat(BeatFraction.Quarter))
|
|
71
|
+
sound += -25
|
|
72
72
|
}
|
|
73
|
-
sound = music.noteFrequency(Note.A)
|
|
74
|
-
})
|
|
73
|
+
sound = music.noteFrequency(Note.A)
|
|
74
|
+
})
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
Click `|Download|` again and play both bananas. It's a fruit jam session!
|
|
@@ -73,7 +73,7 @@ Your banana keyboard is ready!
|
|
|
73
73
|
|
|
74
74
|
Connect your @boardname@ to your computer using your USB cable and run this script:
|
|
75
75
|
```blocks
|
|
76
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
76
|
+
input.onPinPressed(TouchPin.P1, function () {
|
|
77
77
|
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter));
|
|
78
78
|
});
|
|
79
79
|
```
|
|
@@ -25,10 +25,10 @@ Before creating the code for the game actions, let's first add some controls so
|
|
|
25
25
|
```blocks
|
|
26
26
|
let bird: game.LedSprite = null
|
|
27
27
|
|
|
28
|
-
input.onButtonPressed(Button.A, ()
|
|
28
|
+
input.onButtonPressed(Button.A, function () {
|
|
29
29
|
bird.change(LedSpriteProperty.Y, -1)
|
|
30
30
|
})
|
|
31
|
-
input.onButtonPressed(Button.B, ()
|
|
31
|
+
input.onButtonPressed(Button.B, function () {
|
|
32
32
|
bird.change(LedSpriteProperty.Y, 1)
|
|
33
33
|
})
|
|
34
34
|
```
|
|
@@ -79,11 +79,11 @@ for (let index = 0; index <= 4; index++) {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
input.onButtonPressed(Button.A, ()
|
|
82
|
+
input.onButtonPressed(Button.A, function () {
|
|
83
83
|
bird.change(LedSpriteProperty.Y, -1)
|
|
84
84
|
})
|
|
85
85
|
|
|
86
|
-
input.onButtonPressed(Button.B, ()
|
|
86
|
+
input.onButtonPressed(Button.B, function () {
|
|
87
87
|
bird.change(LedSpriteProperty.Y, 1)
|
|
88
88
|
})
|
|
89
89
|
```
|
|
@@ -97,7 +97,7 @@ Right click on the ``||value||`` block and rename it to ``||obstacle||``
|
|
|
97
97
|
```blocks
|
|
98
98
|
let obstacles: game.LedSprite[] = []
|
|
99
99
|
|
|
100
|
-
basic.forever(()
|
|
100
|
+
basic.forever(function () {
|
|
101
101
|
for (let obstacle of obstacles) {
|
|
102
102
|
obstacle.change(LedSpriteProperty.X, -1)
|
|
103
103
|
}
|
|
@@ -114,7 +114,7 @@ Make obstacles disappear after reaching leftmost corner. Iterate over all obstac
|
|
|
114
114
|
```blocks
|
|
115
115
|
let obstacles: game.LedSprite[] = []
|
|
116
116
|
|
|
117
|
-
basic.forever(()
|
|
117
|
+
basic.forever(function () {
|
|
118
118
|
while (obstacles.length > 0 && obstacles[0].get(LedSpriteProperty.X) == 0) {
|
|
119
119
|
obstacles.removeAt(0).delete()
|
|
120
120
|
}
|
|
@@ -134,7 +134,7 @@ At the moment, our code generates just one vertical obstacle. We need to put obs
|
|
|
134
134
|
let emptyObstacleY = 0
|
|
135
135
|
let obstacles: game.LedSprite[] = []
|
|
136
136
|
|
|
137
|
-
basic.forever(()
|
|
137
|
+
basic.forever(function () {
|
|
138
138
|
while (obstacles.length > 0 && obstacles[0].get(LedSpriteProperty.X) == 0) {
|
|
139
139
|
obstacles.removeAt(0).delete()
|
|
140
140
|
}
|
|
@@ -159,7 +159,7 @@ let ticks = 0
|
|
|
159
159
|
let emptyObstacleY = 0
|
|
160
160
|
let obstacles: game.LedSprite[] = []
|
|
161
161
|
|
|
162
|
-
basic.forever(()
|
|
162
|
+
basic.forever(function () {
|
|
163
163
|
while (obstacles.length > 0 && obstacles[0].get(LedSpriteProperty.X) == 0) {
|
|
164
164
|
obstacles.removeAt(0).delete()
|
|
165
165
|
}
|
|
@@ -190,7 +190,7 @@ let ticks = 0
|
|
|
190
190
|
let emptyObstacleY = 0
|
|
191
191
|
let obstacles: game.LedSprite[] = []
|
|
192
192
|
|
|
193
|
-
basic.forever(()
|
|
193
|
+
basic.forever(function () {
|
|
194
194
|
while (obstacles.length > 0 && obstacles[0].get(LedSpriteProperty.X) == 0) {
|
|
195
195
|
obstacles.removeAt(0).delete()
|
|
196
196
|
}
|
|
@@ -226,17 +226,17 @@ let emptyObstacleY = 0
|
|
|
226
226
|
let obstacles: game.LedSprite[] = []
|
|
227
227
|
let index = 0
|
|
228
228
|
let bird: game.LedSprite = null
|
|
229
|
-
input.onButtonPressed(Button.A, ()
|
|
229
|
+
input.onButtonPressed(Button.A, function () {
|
|
230
230
|
bird.change(LedSpriteProperty.Y, -1)
|
|
231
231
|
})
|
|
232
|
-
input.onButtonPressed(Button.B, ()
|
|
232
|
+
input.onButtonPressed(Button.B, function () {
|
|
233
233
|
bird.change(LedSpriteProperty.Y, 1)
|
|
234
234
|
})
|
|
235
235
|
index = 0
|
|
236
236
|
obstacles = []
|
|
237
237
|
bird = game.createSprite(0, 2)
|
|
238
238
|
bird.set(LedSpriteProperty.Blink, 300)
|
|
239
|
-
basic.forever(()
|
|
239
|
+
basic.forever(function () {
|
|
240
240
|
while (obstacles.length > 0 && obstacles[0].get(LedSpriteProperty.X) == 0) {
|
|
241
241
|
obstacles.removeAt(0).delete()
|
|
242
242
|
}
|
|
@@ -34,7 +34,7 @@ When the clock reaches "noon" (let's pick `8` as noon), we turn on the screen br
|
|
|
34
34
|
```block
|
|
35
35
|
// the clock ticker
|
|
36
36
|
let clock = 0
|
|
37
|
-
basic.forever(()
|
|
37
|
+
basic.forever(function () {
|
|
38
38
|
// if clock "hits noon", flash the screen
|
|
39
39
|
if (clock >= 8) {
|
|
40
40
|
// flash
|
|
@@ -61,7 +61,7 @@ When a firefly flashes, it also sends a number over radio using ``||radio:radio
|
|
|
61
61
|
```block
|
|
62
62
|
// the clock ticker
|
|
63
63
|
let clock = 0
|
|
64
|
-
basic.forever(()
|
|
64
|
+
basic.forever(function () {
|
|
65
65
|
// if clock "hits noon", flash the screen
|
|
66
66
|
if (clock >= 8) {
|
|
67
67
|
// notify neighbors
|
|
@@ -111,7 +111,7 @@ radio.onReceivedNumber(function (receivedNumber) {
|
|
|
111
111
|
// advance clock to catch up neighbors
|
|
112
112
|
clock += 1
|
|
113
113
|
})
|
|
114
|
-
basic.forever(()
|
|
114
|
+
basic.forever(function () {
|
|
115
115
|
// if clock hits noon, flash the screen
|
|
116
116
|
if (clock >= 8) {
|
|
117
117
|
// notify neighbors
|
|
@@ -53,7 +53,7 @@ acceleration of gravity.
|
|
|
53
53
|
|
|
54
54
|
## Step 1: Graphing acceleration
|
|
55
55
|
```blocks
|
|
56
|
-
basic.forever(()
|
|
56
|
+
basic.forever(function () {
|
|
57
57
|
led.plotBarGraph(input.acceleration(Dimension.Y), 1023)
|
|
58
58
|
})
|
|
59
59
|
```
|
|
@@ -76,11 +76,11 @@ Try graphing the acceleration along the **X** and **Z** axis. Can you explain th
|
|
|
76
76
|
## Step 2: Mapping acceleration to Beat
|
|
77
77
|
**@boardname@ sensors produce signal values between 0 to 1023. The *[map block](/reference/pins/map)* converts the signal to a desired range.**
|
|
78
78
|
```blocks
|
|
79
|
-
basic.forever(()
|
|
79
|
+
basic.forever(function () {
|
|
80
80
|
music.setTempo(pins.map(Math.abs(input.acceleration(Dimension.Y)),
|
|
81
81
|
0, 1023,
|
|
82
82
|
60, 320))
|
|
83
|
-
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
|
|
83
|
+
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
|
|
84
84
|
})
|
|
85
85
|
```
|
|
86
86
|
|
|
@@ -94,14 +94,14 @@ basic.forever(() => {
|
|
|
94
94
|
**Put it all together!**
|
|
95
95
|
|
|
96
96
|
```blocks
|
|
97
|
-
basic.forever(()
|
|
97
|
+
basic.forever(function () {
|
|
98
98
|
music.setTempo(pins.map(Math.abs(input.acceleration(Dimension.Y)),
|
|
99
99
|
0, 1023,
|
|
100
100
|
60, 320))
|
|
101
101
|
music.playTone(
|
|
102
102
|
input.lightLevel() * 25,
|
|
103
103
|
music.beat(BeatFraction.Quarter)
|
|
104
|
-
)
|
|
104
|
+
)
|
|
105
105
|
})
|
|
106
106
|
```
|
|
107
107
|
**Combine the code above with the light sensor tone control code from the previous activity**
|
|
@@ -37,7 +37,7 @@ Headphones
|
|
|
37
37
|
. # . # .
|
|
38
38
|
. # # # .
|
|
39
39
|
`);
|
|
40
|
-
input.onButtonPressed(Button.A, ()
|
|
40
|
+
input.onButtonPressed(Button.A, function () {})
|
|
41
41
|
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
|
|
42
42
|
music.rest(music.beat(BeatFraction.Whole))
|
|
43
43
|
music.beat(BeatFraction.Quarter)
|
|
@@ -52,7 +52,7 @@ Open @homeurl@ in your web browser
|
|
|
52
52
|
. # # # .
|
|
53
53
|
. # . # .
|
|
54
54
|
. # # # .
|
|
55
|
-
`)
|
|
55
|
+
`)
|
|
56
56
|
```
|
|
57
57
|
From **Basics**, drag a **show LEDs** block into the coding area
|
|
58
58
|
* Create a face with LEDs
|
|
@@ -63,7 +63,7 @@ Follow the instructions to move the code to your @boardname@.
|
|
|
63
63
|
|
|
64
64
|
## Step 2: Add Smiley LED Button Events
|
|
65
65
|
```blocks
|
|
66
|
-
input.onButtonPressed(Button.A, ()
|
|
66
|
+
input.onButtonPressed(Button.A, function () {
|
|
67
67
|
basic.showLeds(`
|
|
68
68
|
. # . # .
|
|
69
69
|
. . . . .
|
|
@@ -72,7 +72,7 @@ input.onButtonPressed(Button.A, () => {
|
|
|
72
72
|
. # # # .
|
|
73
73
|
`)
|
|
74
74
|
})
|
|
75
|
-
input.onButtonPressed(Button.B, ()
|
|
75
|
+
input.onButtonPressed(Button.B, function () {
|
|
76
76
|
basic.showLeds(`
|
|
77
77
|
. # . # .
|
|
78
78
|
. . . . .
|
|
@@ -115,7 +115,7 @@ Connect the headphones with crocodile clips
|
|
|
115
115
|
The **play tone** block allows a range letter note tones from **C** to **B5**.
|
|
116
116
|
Songs are played using sequences notes. Like the beginning of a birthday song (C, C, D, C, F, E).
|
|
117
117
|
```blocks
|
|
118
|
-
input.onButtonPressed(Button.A, ()
|
|
118
|
+
input.onButtonPressed(Button.A, function () {
|
|
119
119
|
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
|
|
120
120
|
music.rest(music.beat(BeatFraction.Whole))
|
|
121
121
|
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
|
|
@@ -133,7 +133,7 @@ input.onButtonPressed(Button.A, () => {
|
|
|
133
133
|
## ~
|
|
134
134
|
## Step 4: Add Tone Playing Events for Buttons A & B
|
|
135
135
|
```blocks
|
|
136
|
-
input.onButtonPressed(Button.A, ()
|
|
136
|
+
input.onButtonPressed(Button.A, function () {
|
|
137
137
|
basic.showLeds(`
|
|
138
138
|
. # . # .
|
|
139
139
|
. . . . .
|
|
@@ -143,7 +143,7 @@ input.onButtonPressed(Button.A, () => {
|
|
|
143
143
|
`)
|
|
144
144
|
music.playTone(Note.A, music.beat(BeatFraction.Whole))
|
|
145
145
|
})
|
|
146
|
-
input.onButtonPressed(Button.B, ()
|
|
146
|
+
input.onButtonPressed(Button.B, function () {
|
|
147
147
|
basic.showLeds(`
|
|
148
148
|
. # . # .
|
|
149
149
|
. . . . .
|
|
@@ -33,7 +33,7 @@ The forever loop really does run forever. The forever loop is useful when there
|
|
|
33
33
|
## Blocks
|
|
34
34
|
|
|
35
35
|
```cards
|
|
36
|
-
basic.forever(()
|
|
36
|
+
basic.forever(function () {})
|
|
37
37
|
input.lightLevel()
|
|
38
38
|
led.plotBarGraph(0, 255)
|
|
39
39
|
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
|
|
@@ -41,7 +41,7 @@ music.playTone(Note.C, music.beat(BeatFraction.Quarter))
|
|
|
41
41
|
|
|
42
42
|
## Step 1: Create a light level detector
|
|
43
43
|
```blocks
|
|
44
|
-
basic.forever(()
|
|
44
|
+
basic.forever(function () {
|
|
45
45
|
led.plotBarGraph(input.lightLevel(), 255)
|
|
46
46
|
})
|
|
47
47
|
```
|
|
@@ -80,7 +80,7 @@ music.playTone(261, music.beat(BeatFraction.Half))
|
|
|
80
80
|
|
|
81
81
|
## Step 3: Multiply Frequency using Math blocks
|
|
82
82
|
```blocks
|
|
83
|
-
input.onButtonPressed(Button.A, ()
|
|
83
|
+
input.onButtonPressed(Button.A, function () {
|
|
84
84
|
music.playTone(261 * 2, music.beat(BeatFraction.Half))
|
|
85
85
|
})
|
|
86
86
|
```
|
|
@@ -95,7 +95,7 @@ Create a **play tone** block using a **Math** section, **multiplication** block
|
|
|
95
95
|
|
|
96
96
|
## Step 4: Control the Frequency with the light input
|
|
97
97
|
```blocks
|
|
98
|
-
basic.forever(()
|
|
98
|
+
basic.forever(function () {
|
|
99
99
|
music.playTone(input.lightLevel() * 25, music.beat(BeatFraction.Quarter))
|
|
100
100
|
})
|
|
101
101
|
```
|
|
@@ -22,9 +22,9 @@ Use pin press to switch guitar play on/off
|
|
|
22
22
|
|
|
23
23
|
```cards
|
|
24
24
|
let on = false
|
|
25
|
-
on
|
|
25
|
+
on
|
|
26
26
|
if (on) { } else {}
|
|
27
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
27
|
+
input.onPinPressed(TouchPin.P1, function () {})
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
|
|
@@ -43,13 +43,13 @@ input.onPinPressed(TouchPin.P1, () => {})
|
|
|
43
43
|
## Step 1: Pin Press Test
|
|
44
44
|
|
|
45
45
|
```blocks
|
|
46
|
-
input.onPinPressed(TouchPin.P0, ()
|
|
46
|
+
input.onPinPressed(TouchPin.P0, function () {
|
|
47
47
|
basic.showNumber(0)
|
|
48
48
|
})
|
|
49
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
49
|
+
input.onPinPressed(TouchPin.P1, function () {
|
|
50
50
|
basic.showNumber(1)
|
|
51
51
|
})
|
|
52
|
-
input.onPinPressed(TouchPin.P2, ()
|
|
52
|
+
input.onPinPressed(TouchPin.P2, function () {
|
|
53
53
|
basic.showNumber(2)
|
|
54
54
|
})
|
|
55
55
|
```
|
|
@@ -88,14 +88,14 @@ https://youtu.be/YkymZGNmkrE
|
|
|
88
88
|
**between ON and OFF**
|
|
89
89
|
```blocks
|
|
90
90
|
let on = false
|
|
91
|
-
basic.forever(()
|
|
91
|
+
basic.forever(function () {
|
|
92
92
|
if (on == true) {
|
|
93
93
|
basic.showString("ON")
|
|
94
94
|
} else {
|
|
95
95
|
basic.showString("OFF")
|
|
96
96
|
}
|
|
97
97
|
})
|
|
98
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
98
|
+
input.onPinPressed(TouchPin.P1, function () {
|
|
99
99
|
if (on == true) {
|
|
100
100
|
on = false
|
|
101
101
|
} else {
|
|
@@ -110,10 +110,10 @@ input.onPinPressed(TouchPin.P1, () => {
|
|
|
110
110
|
**Test by touching `P1` to toggle the LED message between ON and OFF**
|
|
111
111
|
|
|
112
112
|
*Final code*
|
|
113
|
-
TODO: do we want to use `on = !on
|
|
113
|
+
TODO: do we want to use `on = !on` or be more direct in flipping the switch? `on = true` or `on = false`
|
|
114
114
|
```blocks
|
|
115
115
|
let on = false
|
|
116
|
-
basic.forever(()
|
|
116
|
+
basic.forever(function () {
|
|
117
117
|
if (on) {
|
|
118
118
|
music.setTempo(pins.map(Math.abs(input.acceleration(Dimension.Y)),
|
|
119
119
|
0, 1023,
|
|
@@ -121,13 +121,13 @@ basic.forever(() => {
|
|
|
121
121
|
music.playTone(
|
|
122
122
|
input.lightLevel() * 25,
|
|
123
123
|
music.beat(BeatFraction.Quarter)
|
|
124
|
-
)
|
|
124
|
+
)
|
|
125
125
|
} else {
|
|
126
126
|
music.rest(music.beat())
|
|
127
127
|
}
|
|
128
128
|
})
|
|
129
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
130
|
-
on = !on
|
|
129
|
+
input.onPinPressed(TouchPin.P1, function () {
|
|
130
|
+
on = !on
|
|
131
131
|
})
|
|
132
132
|
```
|
|
133
133
|
## Now Play!
|
|
@@ -9,17 +9,17 @@ Have you ever tried to making beat box sounds based on the light level? Let's tr
|
|
|
9
9
|
Let's start by playing music when the **A** button is pressed. To do that, register an event handler that will execute whenever you click on the **A** button. Open the ``||input:Input||`` drawer and get out an ``||input:on button A pressed||`` block. Next, add a ``||music:rest||`` to play nothing for `1/16` of a beat.
|
|
10
10
|
|
|
11
11
|
```blocks
|
|
12
|
-
input.onButtonPressed(Button.A, ()
|
|
13
|
-
music.rest(music.beat(BeatFraction.Sixteenth))
|
|
12
|
+
input.onButtonPressed(Button.A, function () {
|
|
13
|
+
music.rest(music.beat(BeatFraction.Sixteenth))
|
|
14
14
|
});
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
We also want to add a variable where you can store data. Name the variable ``light`` and ``||variables:set||`` the value of the variable to the ``||input:light level||`` block from the ``||input:Input||`` drawer. This will get the light level as some value between `0` (dark) and `255` (bright). The light is measured by using various LEDs from the screen. Your code will look like this:
|
|
18
18
|
|
|
19
19
|
```blocks
|
|
20
|
-
input.onButtonPressed(Button.A, ()
|
|
21
|
-
music.rest(music.beat(BeatFraction.Sixteenth))
|
|
22
|
-
let light = input.lightLevel()
|
|
20
|
+
input.onButtonPressed(Button.A, function () {
|
|
21
|
+
music.rest(music.beat(BeatFraction.Sixteenth))
|
|
22
|
+
let light = input.lightLevel()
|
|
23
23
|
});
|
|
24
24
|
```
|
|
25
25
|
|
|
@@ -29,14 +29,14 @@ Click on the ``||logic:Logic||`` drawer and find an ``||logic:if||`` block to us
|
|
|
29
29
|
* If this condition is not `true`, play ``||music:ring tone||`` for ``Middle A``
|
|
30
30
|
|
|
31
31
|
```blocks
|
|
32
|
-
input.onButtonPressed(Button.A, ()
|
|
33
|
-
music.rest(music.beat(BeatFraction.Sixteenth))
|
|
34
|
-
let light = input.lightLevel()
|
|
32
|
+
input.onButtonPressed(Button.A, function () {
|
|
33
|
+
music.rest(music.beat(BeatFraction.Sixteenth))
|
|
34
|
+
let light = input.lightLevel()
|
|
35
35
|
if (light < 25) {
|
|
36
|
-
music.ringTone(music.noteFrequency(Note.C))
|
|
36
|
+
music.ringTone(music.noteFrequency(Note.C))
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
music.ringTone(music.noteFrequency(Note.A))
|
|
39
|
+
music.ringTone(music.noteFrequency(Note.A))
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
```
|
|
@@ -50,26 +50,26 @@ Now, we want to add more conditional statements by clicking on the **(+)** at th
|
|
|
50
50
|
* If these conditions are not true, play ``||music:ring tone||`` ``Middle A``
|
|
51
51
|
|
|
52
52
|
```blocks
|
|
53
|
-
input.onButtonPressed(Button.A, ()
|
|
54
|
-
music.rest(music.beat(BeatFraction.Sixteenth))
|
|
55
|
-
let light = input.lightLevel()
|
|
53
|
+
input.onButtonPressed(Button.A, function () {
|
|
54
|
+
music.rest(music.beat(BeatFraction.Sixteenth))
|
|
55
|
+
let light = input.lightLevel()
|
|
56
56
|
if (light < 25) {
|
|
57
|
-
music.ringTone(music.noteFrequency(Note.C))
|
|
57
|
+
music.ringTone(music.noteFrequency(Note.C))
|
|
58
58
|
}
|
|
59
59
|
else if (light < 50) {
|
|
60
|
-
music.ringTone(music.noteFrequency(Note.D))
|
|
60
|
+
music.ringTone(music.noteFrequency(Note.D))
|
|
61
61
|
}
|
|
62
62
|
else if (light < 100) {
|
|
63
|
-
music.ringTone(music.noteFrequency(Note.E))
|
|
63
|
+
music.ringTone(music.noteFrequency(Note.E))
|
|
64
64
|
}
|
|
65
65
|
else if (light < 150) {
|
|
66
|
-
music.ringTone(music.noteFrequency(Note.F))
|
|
66
|
+
music.ringTone(music.noteFrequency(Note.F))
|
|
67
67
|
}
|
|
68
68
|
else if (light < 180) {
|
|
69
|
-
music.ringTone(music.noteFrequency(Note.G))
|
|
69
|
+
music.ringTone(music.noteFrequency(Note.G))
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
music.ringTone(music.noteFrequency(Note.A))
|
|
72
|
+
music.ringTone(music.noteFrequency(Note.A))
|
|
73
73
|
}
|
|
74
74
|
});
|
|
75
75
|
```
|
|
@@ -21,7 +21,7 @@ radio.setTransmitPower(6)
|
|
|
21
21
|
The beacon just needs to send a radio message every now and then. So, to pace the transmits and give some visual feedback, we add some ``||basic:show icon||`` blocks to animate the screen.
|
|
22
22
|
|
|
23
23
|
```blocks
|
|
24
|
-
basic.forever(()
|
|
24
|
+
basic.forever(function () {
|
|
25
25
|
radio.sendNumber(0)
|
|
26
26
|
basic.showIcon(IconNames.Heart)
|
|
27
27
|
basic.showIcon(IconNames.SmallHeart)
|
|
@@ -47,7 +47,7 @@ radio.onReceivedNumber(function (receivedNumber) {
|
|
|
47
47
|
To see the current score, we add an ``||input:on button pressed||`` that displays the score on the screen when the **A** button is pressed.
|
|
48
48
|
|
|
49
49
|
```block
|
|
50
|
-
input.onButtonPressed(Button.A, ()
|
|
50
|
+
input.onButtonPressed(Button.A, function () {
|
|
51
51
|
basic.showNumber(game.score())
|
|
52
52
|
})
|
|
53
53
|
```
|
|
@@ -77,7 +77,7 @@ radio.onReceivedNumber(function (receivedNumber) {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
})
|
|
80
|
-
input.onButtonPressed(Button.A, ()
|
|
80
|
+
input.onButtonPressed(Button.A, function () {
|
|
81
81
|
basic.showNumber(game.score())
|
|
82
82
|
})
|
|
83
83
|
radio.setGroup(1)
|
|
@@ -22,7 +22,7 @@ To determine how far away or how close they are, we use the signal strength of e
|
|
|
22
22
|
let signal = 0;
|
|
23
23
|
radio.onReceivedNumber(function (receivedNumber) {
|
|
24
24
|
signal = radio.receivedPacket(RadioPacketProperty.SignalStrength)
|
|
25
|
-
basic.showNumber(signal)
|
|
25
|
+
basic.showNumber(signal)
|
|
26
26
|
});
|
|
27
27
|
radio.setGroup(1)
|
|
28
28
|
```
|
|
@@ -47,7 +47,7 @@ Here is an example that uses ``-95`` or less for cold, between ``-95`` and ``-80
|
|
|
47
47
|
### ~
|
|
48
48
|
|
|
49
49
|
```blocks
|
|
50
|
-
let signal = 0
|
|
50
|
+
let signal = 0
|
|
51
51
|
radio.onReceivedNumber(function (receivedNumber) {
|
|
52
52
|
signal = radio.receivedPacket(RadioPacketProperty.SignalStrength)
|
|
53
53
|
if (signal < -90) {
|