pxt-microbit 7.1.33 → 7.1.34
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/hexcache/09c1ed868d7d8b474313e6abc88c7a9bede0ca376a507a97886137e8d91372e9.hex +20312 -0
- package/built/hexcache/ba843ecd090c93546c91118ee212273e7b1e104915bfd9146cb18fa1a1c826a6.hex +19712 -0
- package/built/target.js +1 -1
- package/built/target.json +1 -1
- package/built/targetlight.js +1 -1
- package/built/targetlight.json +1 -1
- package/built/web/react-common-authcode.css +1 -1
- package/built/web/react-common-multiplayer.css +1 -1
- package/built/web/react-common-skillmap.css +1 -1
- package/built/web/rtlreact-common-authcode.css +1 -1
- package/built/web/rtlreact-common-multiplayer.css +1 -1
- package/built/web/rtlreact-common-skillmap.css +1 -1
- package/built/web/rtlsemantic.css +1 -1
- package/built/web/semantic.css +1 -1
- package/docs/jacdac.md +1 -2
- package/docs/projects/v2-blow-away.md +34 -34
- package/docs/projects/v2-cat-napping.md +24 -24
- package/docs/projects/v2-clap-lights.md +14 -14
- package/docs/projects/v2-countdown.md +15 -15
- package/docs/projects/v2-morse-chat.md +22 -22
- package/docs/projects/v2-pet-hamster.md +11 -11
- package/docs/projects/v2-play-sound-long.md +3 -3
- package/docs/projects/v2-play-sound.md +2 -2
- package/docs/reference/basic/show-leds.md +7 -3
- package/docs/reference/control/hardware-version.md +10 -2
- package/docs/reference/control.md +0 -1
- package/docs/reference/input/running-time-micros.md +25 -7
- package/docs/reference/input/running-time.md +5 -5
- package/docs/reference/radio/on-data-received.md +3 -3
- package/docs/reference/radio/on-received-buffer.md +2 -2
- package/docs/reference/radio/on-received-number.md +4 -2
- package/docs/reference/radio/on-received-string.md +4 -2
- package/docs/reference/radio/on-received-value.md +4 -2
- package/docs/reference/radio/receive-number.md +3 -3
- package/docs/reference/radio/receive-string.md +3 -3
- package/docs/reference/text.md +1 -18
- package/package.json +2 -2
- package/pxtarget.json +1 -1
- package/built/hexcache/48e233a9e7cb064a9fd68e54c8beff5205dcaa75438efd3aa80b5a8d8b2193b0.hex +0 -19728
- package/built/hexcache/f4ded62c04894faf19f0b018903924088e6564165ff2e1ed59d299b7cde3edef.hex +0 -20330
- /package/built/hexcache/{e756ebe5395e9c7bafe42fe3530efbbbd08f187c6520ef35cf2180fd93231311.hex → 01fcf2f97a9eaeefd82a2ddaa0ca451b2500ff47b8dc92db69fda37deeb1b910.hex} +0 -0
- /package/built/hexcache/{6eb54784e9979c4bc09fc35851ef21b114be086c997f8e82c25fe66fee647fb6.hex → 0ddbecb007986045d0daa6818b319bdc1d05397d2b57d117798c64695cdc9d23.hex} +0 -0
package/docs/jacdac.md
CHANGED
|
@@ -23,8 +23,7 @@ Connect and Code. Instantly.
|
|
|
23
23
|
"name": "Button smasher",
|
|
24
24
|
"description": "How many times can you smash the button in 10 seconds?",
|
|
25
25
|
"url": "https://microsoft.github.io/jacdac-docs/clients/makecode/projects/button-smasher/",
|
|
26
|
-
"imageUrl": "/static/jacdac/button-smasher.jpg"
|
|
27
|
-
"youTubeId": "rlK_8oqMAmo"
|
|
26
|
+
"imageUrl": "/static/jacdac/button-smasher.jpg"
|
|
28
27
|
},
|
|
29
28
|
{
|
|
30
29
|
"name": "Slider Sound Bender",
|
|
@@ -12,8 +12,8 @@ For this tutorial, we'll learn how to blow Haven away 🌬️
|
|
|
12
12
|
|
|
13
13
|
A wild Haven has appeared!
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
■ From the ``||basic:Basic||`` category, find ``||basic:show icon [ ]||`` and add it to your ``||basic:on start||`` container.
|
|
16
|
+
■ Click the heart icon and set it to show a ghost.
|
|
17
17
|
💡 In the ``show icon`` dropdown menu options, you can hover to see what each design is called.
|
|
18
18
|
|
|
19
19
|
```blocks
|
|
@@ -25,7 +25,7 @@ basic.showIcon(IconNames.Ghost)
|
|
|
25
25
|
|
|
26
26
|
## {Loop setup}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
■ From the ``||loops:Loops||`` category, find the ``||loops:repeat [4] times||`` loop and snap it into your empty ``||basic(noclick):forever||`` container.
|
|
29
29
|
💡 Why do we need a [__*repeat loop*__](#repeatLoop "repeat code for a given number of times") when we already have a ``forever`` container? Because ``forever`` has an embedded delay that we want to avoid!
|
|
30
30
|
|
|
31
31
|
```blocks
|
|
@@ -41,9 +41,9 @@ basic.forever(function () {
|
|
|
41
41
|
|
|
42
42
|
Haven hates noise and will blow away if things get too loud. Let's use an [__*if statement*__](#ifstatement "if this condition is met, do something") to check for sounds.
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
■ From ``||logic:Logic||``, grab an ``||logic:if <true> then||`` statement and snap it into your empty ``||loops(noclick):repeat [4] times do||`` loop.
|
|
45
|
+
■ Go back to ``||logic:Logic||`` to get a ``||logic:<[0] [=] [0]>||`` comparison.
|
|
46
|
+
■ Snap ``||logic:<[0] [=] [0]>||`` in to **replace** the ``||logic(noclick):<true>||`` condition for your ``||logic(noclick):if then||`` statement.
|
|
47
47
|
|
|
48
48
|
```blocks
|
|
49
49
|
basic.forever(function () {
|
|
@@ -61,9 +61,9 @@ basic.forever(function () {
|
|
|
61
61
|
|
|
62
62
|
We'll be using a [__*sound threshold*__](#soundThreshold "a number for how loud a sound needs to be to trigger an event. 0 = silence to 255 = maximum noise") to act as Haven's ears.
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
■ From the ``||input:Input||`` category, drag ``||input:sound level||`` in to **replace** the **_left_ ``0``** of your ``||logic(noclick):<[0] [=] [0]>||`` comparison.
|
|
65
|
+
■ Using the dropdown in the **middle** of ``||logic(noclick):[sound level] [=] [0]||``, change the comparison to be **``>``** (greater than).
|
|
66
|
+
■ Finally, have the **right side** of the comparison say ``128`` so your full comparison reads: **``sound level > 128``**.
|
|
67
67
|
💡 This means Haven will hear any sound above ``128``.
|
|
68
68
|
|
|
69
69
|
```blocks
|
|
@@ -81,17 +81,17 @@ basic.forever(function () {
|
|
|
81
81
|
|
|
82
82
|
Let's create some [__*variables*__](#variable "a holder for information that may change") to keep track of Haven's movement.
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
■ In the ``||variables:Variables||`` category, click on ``Make a Variable...`` and make a variable named ``col``.
|
|
85
85
|
💡 ``col`` is short for "column".
|
|
86
|
-
|
|
86
|
+
■ Make **another** variable and name it ``row``.
|
|
87
87
|
|
|
88
88
|
## {Displacing LEDs part 1}
|
|
89
89
|
|
|
90
90
|
To show Haven is blowing away, we want to move a random set of lights sideways.
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
■ Your ``||variables:Variables||`` category should now have the option to ``||variables:set [row] to [0]||``. Drag that block into your empty ``||logic(noclick):if then||`` statement.
|
|
93
|
+
■ From the ``||math:Math||`` category, find ``||math:pick random [0] to [10]||`` and snap that in to **replace** the ``[0]`` in your ``||variables(noclick):set [row] to [0]||`` block.
|
|
94
|
+
■ Change the maximum number from ``10`` to **``4``**.
|
|
95
95
|
💡 We are setting the maximum random value to 4 because the lights on the @boardname@ are numbered 0, 1, 2, 3, and 4 for columns and rows.
|
|
96
96
|
|
|
97
97
|
```blocks
|
|
@@ -108,10 +108,10 @@ basic.forever(function () {
|
|
|
108
108
|
|
|
109
109
|
## {Displacing LEDs part 2}
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
■ Go back into ``||variables:Variables||`` and drag out another ``||variables:set [row] to [0]||``. Place this one below the last one (at **the end**) of your `if then` statement.
|
|
112
|
+
■ Using the **dropdown menu**, set the new block to read ``||variables(noclick):set [col] to [0]||``.
|
|
113
|
+
■ From the ``||math:Math||`` category, grab another ``||math:pick random [0] to [10]||`` and snap that in to **replace** the ``[0]`` in your ``||variables(noclick):set [col] to [0]||`` block.
|
|
114
|
+
■ Change the maximum number from ``10`` to **``4``**.
|
|
115
115
|
|
|
116
116
|
```blocks
|
|
117
117
|
let col = 0
|
|
@@ -131,8 +131,8 @@ basic.forever(function () {
|
|
|
131
131
|
|
|
132
132
|
Time to move some lights around!
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
■ From ``||logic:Logic||``, grab another ``||logic:if <true> then||`` and snap it at the **inside and at the bottom of** your ``||loops(noclick):repeat [4] times do||`` loop, right below your ``||logic(noclick):if [sound level] [>] [128]||`` statement.
|
|
135
|
+
■ From the ``||led:Led||`` category, find ``||led:point x [0] y [0]||`` and drag it in to **replace** the ``||logic(noclick):<true>||`` condition in the **new** ``||logic(noclick):if then||`` statement.
|
|
136
136
|
💡 This block will test if the light is on at the the given ``x`` and ``y`` coordinate points.
|
|
137
137
|
|
|
138
138
|
```blocks
|
|
@@ -154,8 +154,8 @@ basic.forever(function () {
|
|
|
154
154
|
|
|
155
155
|
To create the animation effect of Haven blowing away, we will turn off (or ``unplot``) a light that is on and then turn it on again (``plot`` it) in a different spot.
|
|
156
156
|
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
■ From ``||led:Led||``, grab ``||led:unplot x [0] y [0]||`` and snap it inside the **empty** ``||logic(noclick):if <point x [0] y [0]> then||`` statement.
|
|
158
|
+
■ Go back to ``||led:Led||`` and get ``||led:plot x [0] y [0]||``. Snap that in **beneath** the ``||led(noclick):unplot x [0] y [0]||`` block that you just added.
|
|
159
159
|
|
|
160
160
|
```blocks
|
|
161
161
|
let col = 0
|
|
@@ -177,12 +177,12 @@ basic.forever(function () {
|
|
|
177
177
|
|
|
178
178
|
## Setting variables
|
|
179
179
|
|
|
180
|
-
Notice how you have **three** blocks from the ``||led:Led||`` category. All three have ``||led:x||`` ``[0]`` and ``||led:y||`` ``[0]`` coordinates. In these **two** steps, we will set it so that every ``||led:x||`` is followed by the ``||variables:col||`` variable and every ``||led:y||`` is followed by the ``||variables:row||`` variable.
|
|
181
|
-
|
|
182
|
-
**1.** ``||led:point x [0] y [0]||``
|
|
183
|
-
**2.** ``||led:unplot x [0] y [0]||``
|
|
184
|
-
**3.** ``||led:plot x [0] y [0]||``
|
|
185
|
-
|
|
180
|
+
Notice how you have **three** blocks from the ``||led:Led||`` category. All three have ``||led(noclick):x||`` ``[0]`` and ``||led(noclick):y||`` ``[0]`` coordinates. In these **two** steps, we will set it so that every ``||led(noclick):x||`` is followed by the ``||variables:col||`` variable and every ``||led(noclick):y||`` is followed by the ``||variables(noclick):row||`` variable.
|
|
181
|
+
■ From ``||variables:Variables||``, get three copies of ``||variables:col||``, and use them to **replace the ``x`` values** in the following three blocks:
|
|
182
|
+
**1.** ``||led(noclick):point x [0] y [0]||``
|
|
183
|
+
**2.** ``||led(noclick):unplot x [0] y [0]||``
|
|
184
|
+
**3.** ``||led(noclick):plot x [0] y [0]||``
|
|
185
|
+
■ Go into ``||variables:Variables||``, get three copies of ``||variables:row||``, and use them to **replace the ``y`` values** in the same three blocks.
|
|
186
186
|
|
|
187
187
|
```blocks
|
|
188
188
|
let col = 0
|
|
@@ -206,10 +206,10 @@ basic.forever(function () {
|
|
|
206
206
|
|
|
207
207
|
Right now, we are unplotting and replotting in the same spot. What we want to do is move the lights we're turning back on just a smidge to the right every time until there's nothing left on the grid.
|
|
208
208
|
|
|
209
|
-
|
|
210
|
-
💡 If you move your entire ``||basic:forever||`` container, you should find a greyed out ``col`` variable in your workspace.
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
■ From ``||math:Math||``, find the ``||math:[0] [+] [0]||`` operation and use it to **replace** ``||variables(noclick):col||`` in your ``||led(noclick):plot x [col] y [row]||`` block.
|
|
210
|
+
💡 If you move your entire ``||basic(noclick):forever||`` container, you should find a greyed out ``col`` variable in your workspace.
|
|
211
|
+
■ Take the greyed out ``||variables(noclick):col||`` variable (or get a new one) and use it to **replace** the **_first_ ``[0]``** so the operation reads ``||math(noclick):[col] [+] [0]||``.
|
|
212
|
+
■ Replace the **_second_ ``[0]``** with **``[1]``** so the operation reads ``||math(noclick):[col] [+] [1]||``.
|
|
213
213
|
|
|
214
214
|
```blocks
|
|
215
215
|
let col = 0
|
|
@@ -233,8 +233,8 @@ basic.forever(function () {
|
|
|
233
233
|
|
|
234
234
|
Check out the simulator!
|
|
235
235
|
|
|
236
|
-
|
|
237
|
-
|
|
236
|
+
■ Click on the pink bar underneath the microphone icon. Drag it above the sound number you chose (we used ``128``!) to blow Haven away.
|
|
237
|
+
■ If you have a new @boardname@ (the one with the **shiny gold** logo at the top), download this code and try it out!
|
|
238
238
|
💡 Blow close to the @boardname@ and watch Haven swoosh away 💨
|
|
239
239
|
💡 Use your @boardname@'s reset button (it's on the back!) to bring Haven back 👻
|
|
240
240
|
|
|
@@ -10,9 +10,9 @@ Lychee the cat loves the sun and wants to know if your home has a good sunbathin
|
|
|
10
10
|
|
|
11
11
|
First, we want to make sure we know when our micro:bit is collecting data. To do this, let's create a [__*boolean*__](#boolean "something that is only true or false") [__*variable*__](#variable "a holder for information that may change") and use it to track when the @boardname@ is logging data. We'll start with the logging variable set to false.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
■ In the ``||variables:Variables||`` category, click on ``Make a Variable...`` and make a variable named ``logging``.
|
|
14
|
+
■ From the ``||variables:Variables||`` category, grab the ``||variables:set [logging] to [0]||`` block and snap it into the empty ``||basic(noclick):on start||`` container.
|
|
15
|
+
■ From the ``||logic:Logic||`` category, grab a ``||logic:<false>||`` argument and snap it in to **replace** the ``||variables(noclick):[0]||`` value in your ``||variables(noclick):set [logging] to [0]||`` statement.
|
|
16
16
|
|
|
17
17
|
```blocks
|
|
18
18
|
let logging = false
|
|
@@ -23,8 +23,8 @@ logging = false
|
|
|
23
23
|
|
|
24
24
|
Let's give Lychee some control over when she wants to start and stop logging data on the @boardname@.
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
■ From the ``||input:Input||`` category, grab a ``||input:on button [A] pressed||`` container and drag it into your workspace. Then, grab a ``||variables:set [logging] to [0]||`` block from ``||variables:Varables||`` and snap it inside of your ``||input(noclick):on button [A] pressed||`` container.
|
|
27
|
+
■ From the ``||logic:Logic||`` category, grab a ``||logic:<not []>||`` argument and snap it in to **replace** the ``0`` argument. Go back to the ``||variables:Variables||`` category, grab a ``||variables:logging||`` variable and snap it in to **replace** the empty ``||logic(noclick):<>||`` in the ``||logic(noclick):not <>||`` statement.
|
|
28
28
|
|
|
29
29
|
✋🛑 Take a moment to help Lychee answer the following question: _What is happening every time she presses the A button?_
|
|
30
30
|
|
|
@@ -39,8 +39,8 @@ input.onButtonPressed(Button.A, function () {
|
|
|
39
39
|
|
|
40
40
|
It would help to know when the @boardname@ is logging data and when it isn't. For this step, we will be building out a visual indicator using an [__*if then / else*__](#ifthenelse "runs some code if a boolean condition is true and different code if the condition is false") statement.
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
■ From the ``||logic:Logic||`` category, grab an ``||logic:if <true> then / else||`` statement and snap it in at the **bottom** of your ``||input(noclick):on button [A] pressed||`` container.
|
|
43
|
+
■ From ``||variables:Variables||``, grab a ``||variables:logging||`` variable and snap it in to **replace** the ``||logic(noclick):<true>||`` condition in your ``||logic(noclick):if then / else||`` statement.
|
|
44
44
|
|
|
45
45
|
```blocks
|
|
46
46
|
let logging = false
|
|
@@ -54,8 +54,8 @@ input.onButtonPressed(Button.A, function () {
|
|
|
54
54
|
|
|
55
55
|
## {Set the indicator icon}
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
■ Let's display an image when the @boardname@ is logging data. From the ``||basic:Basic||`` category, grab a ``||basic:show icon [ ]||`` block and snap it into the empty **top container** of your ``||logic(noclick):if then / else||`` statement.
|
|
58
|
+
■ Set it to show the "target" icon (it looks like an empty sun - scroll down to find it!). This will show whenever your @boardname@ is collecting data.
|
|
59
59
|
💡 In the ``show icon`` dropdown menu options, you can hover to see what each design is called.
|
|
60
60
|
|
|
61
61
|
```blocks
|
|
@@ -73,8 +73,8 @@ input.onButtonPressed(Button.A, function () {
|
|
|
73
73
|
|
|
74
74
|
Let's now add an auditory indicator that your @boardname@ is logging data!
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
■ From the ``||music:Music||`` category, grab a ``||music:play sound [dadadum] [in background]||`` block and snap it into the **bottom** of the **top container** of your ``||logic(noclick):if then / else||`` statement.
|
|
77
|
+
■ Click on the ``[dadadum]`` dropdown and select ``nyan``, then set the playback mode to ``||music(noclick):[until done]||``. Your block should now say ``||music(noclick):play melody [nyan] [until done]||``.
|
|
78
78
|
|
|
79
79
|
```blocks
|
|
80
80
|
let logging = false
|
|
@@ -90,7 +90,7 @@ input.onButtonPressed(Button.A, function () {
|
|
|
90
90
|
|
|
91
91
|
## {Logging off indicator}
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
■ Let's clear the board when the @boardname@ is not logging data. From the ``||basic:Basic||`` category, grab a ``||basic:clear screen||`` block and snap it into the empty **bottom container** of your ``||logic(noclick):if then / else||`` statement.
|
|
94
94
|
|
|
95
95
|
```blocks
|
|
96
96
|
let logging = false
|
|
@@ -109,8 +109,8 @@ input.onButtonPressed(Button.A, function () {
|
|
|
109
109
|
|
|
110
110
|
Let's set up the data logging for Lychee! In order to get Lychee a good amount of data without running out of memory, we should collect one data point for her every minute.
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
■ From the ``||loops:Loops||`` category, grab a ``||loops:every [500] ms||`` container and add it to your workspace.
|
|
113
|
+
■ Click on the the ``500`` dropdown and select ``1 minute``. <br />
|
|
114
114
|
💡 1 minute is equivalent to 60000ms, which is what the number will automatically change to.
|
|
115
115
|
|
|
116
116
|
```blocks
|
|
@@ -122,8 +122,8 @@ loops.everyInterval(60000, function () {
|
|
|
122
122
|
|
|
123
123
|
Now, let's use an [__*if then*__](#ifthen "runs some code if a boolean condition is true") statement to track when the @boardname@ is logging data.
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
■ From the ``||logic:Logic||`` category, grab a ``||logic:if <true> then||`` statement and snap it into your ``||loops(noclick):every [600000] ms||`` container.
|
|
126
|
+
■ From the ``||variables:Variables||`` category, drag out a ``||variables:logging||`` variable and snap it in to **replace** the ``||logic(noclick):<true>||`` argument in the ``||logic(noclick):if <true> then||`` statement.
|
|
127
127
|
|
|
128
128
|
```blocks
|
|
129
129
|
let logging = false
|
|
@@ -137,9 +137,9 @@ loops.everyInterval(60000, function () {
|
|
|
137
137
|
|
|
138
138
|
Lychee loves her sun spots because they provide a nice, sunny and warm place to nap. So, we'll need to measure the **temperature** and **light** in different places around the house.
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
■ From the ``||datalogger:Data Logger||`` category, grab a ``||datalogger:log data [column [""] value [0]] +||`` block and snap it **inside** the ``||logic(noclick):if [logging] then||`` statement.
|
|
141
|
+
■ Click on the ``""`` after the word ``column`` and type in "``temp``".
|
|
142
|
+
■ From the ``||input:Input||`` category, select the ``||input:temperature (°C)||`` parameter and drag it in to **replace** the ``0`` after the word ``value``.
|
|
143
143
|
|
|
144
144
|
```blocks
|
|
145
145
|
let logging = false
|
|
@@ -155,9 +155,9 @@ loops.everyInterval(60000, function () {
|
|
|
155
155
|
|
|
156
156
|
## {Setting up logging - Part 2}
|
|
157
157
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
■ On the right of the ``||input(noclick):temperature (°C)||`` input that you just snapped in, there is a ➕ button. Click on it. You should now see a new row that says ``||datalogger(noclick):column [""] value [0]||``.
|
|
159
|
+
■ Click on the empty ``""`` after the word ``column`` and type in "``light``".
|
|
160
|
+
■ From the ``||input:Input||`` category, select the ``||input:light level||`` parameter and drag it in to **replace** the ``0`` parameter after the word ``value``.
|
|
161
161
|
|
|
162
162
|
```blocks
|
|
163
163
|
let logging = false
|
|
@@ -176,8 +176,8 @@ loops.everyInterval(60000, function () {
|
|
|
176
176
|
|
|
177
177
|
You did it! If you have a @boardname@ V2 (the one with the **shiny gold** logo at the top), download this code and try it out!
|
|
178
178
|
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
■ Find a sun spot in your house and press the ``A`` button to start logging data - your display should show an icon and play a sound to indicate that you are logging data.
|
|
180
|
+
■ After some time (we recommend at least an hour), press the ``A`` button again to stop logging data - your display should clear to indicate that you are not logging data.
|
|
181
181
|
|
|
182
182
|
## {Reviewing your data @unplugged}
|
|
183
183
|
|
|
@@ -10,7 +10,7 @@ Let's learn how to use a clap 👏 to switch your @boardname@'s lights on and of
|
|
|
10
10
|
|
|
11
11
|
## {Setting up the sound input}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
■ From the ``||input:Input||`` category, find the ``||input:on [loud] sound||`` container and add it to your workspace.
|
|
14
14
|
|
|
15
15
|
```blocks
|
|
16
16
|
// @highlight
|
|
@@ -23,14 +23,14 @@ input.onSound(DetectedSound.Loud, function () {
|
|
|
23
23
|
|
|
24
24
|
Let's begin by creating a [__*variable*__](#variable "a holder for information that may change") to keep track of whether the @boardname@'s lights are on or off.
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
■ In the ``||variables:Variables||`` category, click on ``Make a Variable...`` and make a variable named ``lightsOn``.
|
|
27
27
|
|
|
28
28
|
## {Displaying LEDs part 1}
|
|
29
29
|
|
|
30
30
|
In this step, we'll be using an [__*if then / else*__](#ifthenelse "runs some code if a Boolean condition is true and different code if the condition is false") statement.
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
■ From the ``||logic:Logic||`` category, grab an ``||logic:if <true> then / else||`` block and snap it into your ``||input(noclick):on [loud] sound||`` container.
|
|
33
|
+
■ Look in the ``||variables:Variables||`` category. Find the new ``||variables:lightsOn||`` variable and snap it in to **replace** the ``||logic(noclick):<true>||`` value in your ``||logic(noclick):if <true> then / else||`` statement.
|
|
34
34
|
|
|
35
35
|
```blocks
|
|
36
36
|
let lightsOn = 0
|
|
@@ -46,8 +46,8 @@ input.onSound(DetectedSound.Loud, function () {
|
|
|
46
46
|
|
|
47
47
|
## {Displaying LEDs part 2}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
■ From ``||basic:Basic||``, grab ``||basic:show leds||`` and snap it into the **top container** of your ``||logic(noclick):if then / else||`` statement.
|
|
50
|
+
■ Set the lights to a pattern you like!
|
|
51
51
|
💡 In the hint, we chose to turn on all of the outside lights. Feel free to make your own design 🎨
|
|
52
52
|
|
|
53
53
|
```blocks
|
|
@@ -69,7 +69,7 @@ input.onSound(DetectedSound.Loud, function () {
|
|
|
69
69
|
|
|
70
70
|
## {Clearing the screen}
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
■ From ``||basic:Basic||``, find ``||basic:clear screen||`` and snap it into the **bottom container** of your ``||logic(noclick):if then / else||`` section.
|
|
73
73
|
💡 This will turn the display off if ``lightsOn`` is **not** ``true``.
|
|
74
74
|
|
|
75
75
|
```blocks
|
|
@@ -94,9 +94,9 @@ input.onSound(DetectedSound.Loud, function () {
|
|
|
94
94
|
|
|
95
95
|
Just like we'd toggle a light switch, each time we clap, we want to **flip** the variable ``lightsOn`` to the **opposite** of what it was before.
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
■ From ``||variables:Variables||``, locate ``||variables:set [lightsOn] to [0]||`` and snap it in at the **very top** of your ``||input(noclick):on [loud] sound||`` container.
|
|
98
|
+
■ From the ``||logic:Logic||`` category, find the ``||logic:not <>||`` operator and use it to **replace the ``[0]``** in ``||variables(noclick):set [lightsOn] to [0]||``.
|
|
99
|
+
■ From ``||variables:Variables||``, grab ``||variables:lightsOn||`` and snap it into the **empty part** of the ``||logic(noclick):not <>||`` operator.
|
|
100
100
|
|
|
101
101
|
```blocks
|
|
102
102
|
let lightsOn = false
|
|
@@ -119,16 +119,16 @@ input.onSound(DetectedSound.Loud, function () {
|
|
|
119
119
|
|
|
120
120
|
## {Testing in the simulator}
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
■ Check out the simulator!
|
|
123
|
+
■ Click on the pink slider bar beneath the microphone icon and drag it up and down.
|
|
124
124
|
💡 Right now, your @boardname@ thinks that anything above 128 is loud. Every time the sound goes > 128, your lights should switch on/off.
|
|
125
125
|
|
|
126
126
|
## {Set loud sound threshold}
|
|
127
127
|
|
|
128
128
|
Your @boardname@ might detect sounds when you don't want it to. Setting a [__*sound threshold*__](#soundThreshold "a number for how loud a sound needs to be to trigger an event. 0 = silence to 255 = maximum noise") could help 🔉🔊
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
■ Click on the ``||input:Input||`` category. A new category should show up beneath it called ``||input:...more||``.
|
|
131
|
+
■ From ``||input:...more||``, grab ``||input:set [loud] sound threshold to [128]||`` and snap it into your **empty** ``||basic(noclick):on start||`` container.
|
|
132
132
|
💡 Try to change the value of your sound threshold so that every time you clap, your lights will turn on if they are off and vice versa.
|
|
133
133
|
|
|
134
134
|
```blocks
|
|
@@ -13,8 +13,8 @@ Let's create a musical countdown using the new @boardname@ with sound!
|
|
|
13
13
|
|
|
14
14
|
We'll begin by using a [__*for loop*__](#forLoop "repeat code for a given number of times using an index") to recreate the same sound 3 times.
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
■ From the ``||loops:Loops||`` category in your toolbox, find the ``||loops:for [index] from 0 to [4]||`` loop and add it to your ``||basic(noclick):on start||`` container.
|
|
17
|
+
■ Change your loop to count from ``0`` to **``2``**.
|
|
18
18
|
💡 This means the loop will count 0-1-2 instead of what we want, which is 3-2-1. We will worry about this later!
|
|
19
19
|
|
|
20
20
|
```blocks
|
|
@@ -26,9 +26,9 @@ for (let index = 0; index <= 2; index++) {
|
|
|
26
26
|
|
|
27
27
|
## {Play music}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
■ From ``||music:Music||``, grab ``||music:play tone [Middle C] for [1 beat] [until done]||`` and snap it into your empty ``for`` loop.
|
|
30
30
|
💡 Your simulator might start playing music. You can mute it if distracting.
|
|
31
|
-
|
|
31
|
+
■ 1 beat is a little long. Use the **dropdown** to set the tone to play for ``||music(noclick):1/4 beat||``.
|
|
32
32
|
|
|
33
33
|
```blocks
|
|
34
34
|
for (let index = 0; index <= 2; index++) {
|
|
@@ -41,9 +41,9 @@ for (let index = 0; index <= 2; index++) {
|
|
|
41
41
|
|
|
42
42
|
With every tone, we also want to **display** our countdown.
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
■ From ``||basic:Basic||``, find ``||basic:show number [0]||`` and snap it in at the **bottom** of your ``for`` loop.
|
|
45
|
+
■ From your ``||loops(noclick):for [index] from 0 to [2]||`` loop condition, click and drag out the **red** ``||variables(noclick):index||`` variable.
|
|
46
|
+
■ Use the ``||variables(noclick):index||`` that you dragged out to **replace** the ``0`` in ``||basic(noclick):show number [0]||``.
|
|
47
47
|
|
|
48
48
|
```blocks
|
|
49
49
|
for (let index = 0; index <= 2; index++) {
|
|
@@ -57,11 +57,11 @@ for (let index = 0; index <= 2; index++) {
|
|
|
57
57
|
|
|
58
58
|
If you take a look at your simulator, you'll notice the @boardname@ flashing 0-1-2. We want it to say 3-2-1! Let's learn a trick to change that.
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
■ From the ``||math:Math||`` category, snap ``||math:[0] - [0]||`` in to **replace** ``||variables(noclick):index||`` in your ``||basic(noclick):show number [index]||`` block.
|
|
61
61
|
💡 You should now have a greyed out ``index`` variable in your workspace. We'll use that in the next step.
|
|
62
|
-
|
|
63
|
-
💡 Can't find ``||variables:index||``? Try moving your ``||basic:on start||`` container to see if ``||variables:
|
|
64
|
-
|
|
62
|
+
■ Pick up the greyed out ``||variables(noclick):index||`` variable and snap it in to the **right side** of your ``||math:[0] - [0]||`` operator.
|
|
63
|
+
💡 Can't find ``||variables(noclick):index||``? Try moving your ``||basic(noclick):on start||`` container to see if ``||variables(noclick):index||`` is hiding behind it!
|
|
64
|
+
■ Set the **left side** of your ``||math(noclick):[0]-[index]||`` operator to **``3``**.
|
|
65
65
|
💡 Why does this work? Every time we loop, our ``index`` variable will grow by 1 and our @boardname@ will output: 3-0 = **3** ➡️ 3-1 = **2** ➡️ 3-2 = **1**!
|
|
66
66
|
|
|
67
67
|
```blocks
|
|
@@ -74,8 +74,8 @@ for (let index = 0; index <= 2; index++) {
|
|
|
74
74
|
|
|
75
75
|
## {Printing "GO!"}
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
■ From ``||basic:Basic||``, grab ``||basic:show string ["Hello!"]||`` and snap it into the **very bottom** of your ``||basic(noclick):on start||`` container.
|
|
78
|
+
■ Replace ``Hello!`` with the word ``GO!``
|
|
79
79
|
|
|
80
80
|
```blocks
|
|
81
81
|
for (let index = 0; index <= 2; index++) {
|
|
@@ -88,9 +88,9 @@ basic.showString("GO!")
|
|
|
88
88
|
|
|
89
89
|
## {Adding a "GO!" noise}
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
■ From the ``||music:Music||`` category, grab ``||music:play tone [Middle C] for [1 beat] [until done]||`` and place it **above** your ``||basic(noclick):show string ["GO!"]||`` block and **below** your ``||loops(noclick):for||`` loop.
|
|
92
92
|
💡 This will let your @boardname@ play the sound and show ``GO!`` at the same time.
|
|
93
|
-
|
|
93
|
+
■ Set the ``||music(noclick):tone||`` to be ``Middle G``.
|
|
94
94
|
💡 ``Middle G`` is also tone ``392``.
|
|
95
95
|
|
|
96
96
|
```blocks
|
|
@@ -21,8 +21,8 @@ Morse code is an alphabet composed of dots (short signals) and dashes (long sign
|
|
|
21
21
|
|
|
22
22
|
hint~
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
■ From the ``||input:Input||`` category in the toolbox, drag an ``||input:on logo [pressed]||`` container into to your workspace.
|
|
25
|
+
■ From the ``||radio:Radio||`` category, get ``||radio:radio send number [0]||`` and snap it into your empty ``||input(noclick):on logo [pressed]||`` container.
|
|
26
26
|
|
|
27
27
|
```blocks
|
|
28
28
|
input.onLogoEvent(TouchButtonEvent.Pressed, function () {
|
|
@@ -32,9 +32,9 @@ input.onLogoEvent(TouchButtonEvent.Pressed, function () {
|
|
|
32
32
|
|
|
33
33
|
## {Sending different messages pt. 1}
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
■ From ``||input:Input||``, grab **another** ``||input:on logo [pressed]||`` container and add it to your workspace.
|
|
36
36
|
💡 This container is greyed out because it matches another. Let's change that!
|
|
37
|
-
|
|
37
|
+
■ On the greyed-out ``||input(noclick):on logo [pressed]||`` container, click on the **``pressed``** dropdown and set it to ``||input(noclick):long pressed||``.
|
|
38
38
|
|
|
39
39
|
```blocks
|
|
40
40
|
// @highlight
|
|
@@ -47,8 +47,8 @@ input.onLogoEvent(TouchButtonEvent.Pressed, function () {
|
|
|
47
47
|
|
|
48
48
|
## {Sending different messages pt. 2}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
■ From the ``||radio:Radio||`` category, get a ``||radio:radio send number [0]||`` block and snap it into your **empty** ``||input(noclick):on logo [long pressed]||`` container.
|
|
51
|
+
■ Set the number to be ``1``.
|
|
52
52
|
|
|
53
53
|
```blocks
|
|
54
54
|
input.onLogoEvent(TouchButtonEvent.LongPressed, function () {
|
|
@@ -64,9 +64,9 @@ input.onLogoEvent(TouchButtonEvent.Pressed, function () {
|
|
|
64
64
|
|
|
65
65
|
To ensure Sky gets the right message, we will use an [__*if then / else*__](#ifthenelse "runs some code if a boolean condition is true and different code if the condition is false") conditional statement.
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
■ From ``||radio:Radio||``, find the ``||radio:on radio received [receivedNumber]||`` container and add it to your workspace.
|
|
68
|
+
■ From ``||logic:Logic||``, grab an ``||logic:if <true> then / else||`` statement and snap it into your **new** ``||radio(noclick):on radio received [receivedNumber]||`` container.
|
|
69
|
+
■ Go back to the ``||logic:Logic||`` category, grab ``||logic:<[0] [=] [0]>||``, and click it in to **replace** the ``||logic(noclick):<true>||`` argument in your ``||logic(noclick):if <true> then / else||`` statement.
|
|
70
70
|
|
|
71
71
|
```blocks
|
|
72
72
|
radio.onReceivedNumber(function (receivedNumber) {
|
|
@@ -81,8 +81,8 @@ radio.onReceivedNumber(function (receivedNumber) {
|
|
|
81
81
|
|
|
82
82
|
## {Conditioning on the input}
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
■ From your ``||radio:on radio received [receivedNumber]||`` container, grab the **``receivedNumber``** input and drag out a copy.
|
|
85
|
+
■ Use your copy of **``receivedNumber``** to replace the ``[0]`` on the **left side** of ``||logic(noclick):<[0] [=] [0]>||``.
|
|
86
86
|
|
|
87
87
|
```blocks
|
|
88
88
|
radio.onReceivedNumber(function (receivedNumber) {
|
|
@@ -97,8 +97,8 @@ radio.onReceivedNumber(function (receivedNumber) {
|
|
|
97
97
|
|
|
98
98
|
## {Displaying a message pt. 1}
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
■ We want to display a dash if the logo is long pressed. From ``||basic:Basic||``, grab ``||basic:show leds||`` and snap it into the empty **bottom container** of your ``||logic(noclick):if then / else||`` statement.
|
|
101
|
+
■ Turn on 3 LEDs in a row to be a dash: -
|
|
102
102
|
|
|
103
103
|
```blocks
|
|
104
104
|
radio.onReceivedNumber(function (receivedNumber) {
|
|
@@ -118,7 +118,7 @@ radio.onReceivedNumber(function (receivedNumber) {
|
|
|
118
118
|
|
|
119
119
|
## {Playing a sound pt. 1}
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
■ From the ``||music:Music||`` category, grab a ``||music:play tone [Middle C] for [1 beat] [until done]||`` block and snap it at the **end** of the **bottom container** in your ``||logic(noclick):if then / else||`` statement.
|
|
122
122
|
|
|
123
123
|
```blocks
|
|
124
124
|
radio.onReceivedNumber(function (receivedNumber) {
|
|
@@ -139,8 +139,8 @@ radio.onReceivedNumber(function (receivedNumber) {
|
|
|
139
139
|
|
|
140
140
|
## {Displaying a message pt. 2}
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
■ We want to display a dot if the logo is pressed. From ``||basic:Basic||``, grab another ``||basic:show leds||`` and snap it into the **top container** of your ``||logic(noclick):if then / else||`` statement.
|
|
143
|
+
■ Turn on a single LED to make a dot: .
|
|
144
144
|
|
|
145
145
|
```blocks
|
|
146
146
|
radio.onReceivedNumber(function (receivedNumber) {
|
|
@@ -168,8 +168,8 @@ radio.onReceivedNumber(function (receivedNumber) {
|
|
|
168
168
|
|
|
169
169
|
## {Playing a sound pt. 2}
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
■ From the ``||music:Music||`` category, grab ``||music:play tone [Middle C] for [1 beat] [until done]||`` and snap it in at the **end** of the **top container** in your ``||logic(noclick):if then / else||`` statement.
|
|
172
|
+
■ Dots are shorter than dashes! Set the tone to play for ``1/4 beat``.
|
|
173
173
|
|
|
174
174
|
```blocks
|
|
175
175
|
radio.onReceivedNumber(function (receivedNumber) {
|
|
@@ -198,7 +198,7 @@ radio.onReceivedNumber(function (receivedNumber) {
|
|
|
198
198
|
|
|
199
199
|
## {Clearing the screens}
|
|
200
200
|
|
|
201
|
-
|
|
201
|
+
■ From ``||basic:Basic||``, find ``||basic:clear screen||`` and snap it in at the **very bottom** of your ``||radio(noclick):on radio received [receivedNumber]||`` container.
|
|
202
202
|
|
|
203
203
|
```blocks
|
|
204
204
|
radio.onReceivedNumber(function (receivedNumber) {
|
|
@@ -232,7 +232,7 @@ radio.onReceivedNumber(function (receivedNumber) {
|
|
|
232
232
|
|
|
233
233
|
Test what you've created. Remember to turn your sound on!
|
|
234
234
|
|
|
235
|
-
|
|
235
|
+
■ Touch the gold **micro:bit logo** at the top of your @boardname@ on the simulator. You'll notice that a second @boardname@ appears. This is the @boardname@ for Sky 🐖
|
|
236
236
|
💡 If your screen is too small, you might not be able to see it.
|
|
237
237
|
|
|
238
238
|
```blocks
|
|
@@ -270,10 +270,10 @@ input.onLogoEvent(TouchButtonEvent.Pressed, function () {
|
|
|
270
270
|
|
|
271
271
|
## {Testing in the simulator - Send message}
|
|
272
272
|
|
|
273
|
-
|
|
273
|
+
■ Touch the logo again to send messages to Sky 🐖
|
|
274
274
|
**Press** to send a dot.
|
|
275
275
|
**Long press** (count to 3!) to send a dash.
|
|
276
|
-
|
|
276
|
+
■ If you have multiple @boardname@s with sound (they have **shiny gold** logos at the top), download this code and try it out!
|
|
277
277
|
|
|
278
278
|
```blocks
|
|
279
279
|
radio.onReceivedNumber(function (receivedNumber) {
|