pxt-microbit 4.0.9 → 4.0.13
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/target-strings.json +2 -1
- package/built/target.js +38 -30
- package/built/target.json +38 -30
- package/built/targetlight.json +5 -5
- package/built/web/rtlsemantic.css +1 -1
- package/built/web/semantic.css +1 -1
- package/docs/blocks/comments.md +131 -0
- package/docs/blocks/loops.md +12 -0
- package/docs/extensions.md +40 -0
- package/docs/projects/SUMMARY.md +7 -1
- package/docs/projects/micro-chat.md +8 -8
- package/docs/projects/mood-radio.md +3 -1
- package/docs/projects/multi-dice.md +8 -6
- package/docs/projects/plot-acceleration.md +2 -2
- package/docs/projects/v2-blow-away.md +317 -0
- package/docs/projects/v2-clap-lights.md +195 -0
- package/docs/projects/v2-countdown.md +151 -0
- package/docs/projects/v2-morse-chat.md +297 -0
- package/docs/projects/v2-pet-hamster.md +165 -0
- package/docs/projects.md +8 -2
- package/docs/reference/basic/forever.md +17 -4
- package/docs/reference/basic/show-number.md +1 -1
- package/docs/reference/loops/every-interval.md +42 -0
- package/docs/reference/radio/on-received-buffer.md +1 -0
- package/docs/reference/radio/on-received-number.md +2 -0
- package/docs/reference/radio/on-received-string.md +1 -0
- package/docs/reference/radio/on-received-value.md +1 -0
- package/docs/reference/radio/received-packet.md +1 -0
- package/docs/reference/radio/send-buffer.md +1 -0
- package/docs/reference/radio/send-string.md +1 -0
- package/docs/reference/radio/set-group.md +8 -0
- package/docs/reference/radio/write-received-packet-to-serial.md +1 -0
- package/docs/reference/radio/write-value-to-serial.md +1 -0
- package/docs/v2tutorials.md +39 -0
- package/package.json +2 -2
- package/targetconfig.json +23 -6
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Clap Lights
|
|
2
|
+
|
|
3
|
+
## 1. Introduction @unplugged
|
|
4
|
+
|
|
5
|
+
The new @boardname@s have a microphone to help them detect sound 🎤
|
|
6
|
+
|
|
7
|
+
Let's learn how to use a clap 👏 to switch your @boardname@'s lights on and off!
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
## 2. Setting up the sound input
|
|
12
|
+
|
|
13
|
+
🔊 **Reacting to sound** 🔊
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
► From the ``||input:Input||`` category, find the ``||input:on [loud] sound||`` container and add it to your workspace.
|
|
18
|
+
|
|
19
|
+
```blocks
|
|
20
|
+
input.onSound(DetectedSound.Loud, function () {
|
|
21
|
+
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 3. Creating a lightsOn variable
|
|
26
|
+
|
|
27
|
+
🤿 **Diving right in** 🤿
|
|
28
|
+
|
|
29
|
+
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.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
► In the ``||variables:Variables||`` category, click on ``Make a Variable...`` and make a variable named ``lightsOn``.
|
|
34
|
+
|
|
35
|
+
## 4. Displaying LEDs part 1
|
|
36
|
+
|
|
37
|
+
🔆 **On or not?** 🌑
|
|
38
|
+
|
|
39
|
+
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.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
► From the ``||logic:Logic||`` category, grab an ``||logic:if <true> then / else||`` block and snap it into your ``||input:on [loud] sound||`` container.
|
|
44
|
+
|
|
45
|
+
► Look in the ``||variables:Variables||`` category. Find the new ``||variables:lightsOn||`` variable and snap it in to **replace** the ``||logic:<true>||`` value in your ``||logic:if <true> then / else||`` statement.
|
|
46
|
+
|
|
47
|
+
```blocks
|
|
48
|
+
let lightsOn = 0
|
|
49
|
+
input.onSound(DetectedSound.Loud, function () {
|
|
50
|
+
// @highlight
|
|
51
|
+
if (lightsOn) {
|
|
52
|
+
|
|
53
|
+
} else {
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## 5. Displaying LEDs part 2
|
|
60
|
+
|
|
61
|
+
🌞 **Lighting the display** 🌞
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
► From ``||basic:Basic||``, grab ``||basic:show leds||`` and snap it into the **top container** of your ``||logic:if then / else||`` statement.
|
|
66
|
+
|
|
67
|
+
► Set the lights to a pattern you like!
|
|
68
|
+
💡 In the hint, we chose to turn on all of the outside lights. Feel free to make your own design 🎨
|
|
69
|
+
|
|
70
|
+
```blocks
|
|
71
|
+
let lightsOn = 0
|
|
72
|
+
input.onSound(DetectedSound.Loud, function () {
|
|
73
|
+
if (lightsOn) {
|
|
74
|
+
// @highlight
|
|
75
|
+
basic.showLeds(`
|
|
76
|
+
# # # # #
|
|
77
|
+
# . . . #
|
|
78
|
+
# . . . #
|
|
79
|
+
# . . . #
|
|
80
|
+
# # # # #
|
|
81
|
+
`)
|
|
82
|
+
} else {
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 6. Clearing the screen
|
|
88
|
+
|
|
89
|
+
► From ``||basic:Basic||``, find ``||basic:clear screen||`` and snap it into the **bottom container** of your ``||logic:if then / else||`` section.
|
|
90
|
+
💡 This will turn the display off if ``lightsOn`` is **not** ``true``.
|
|
91
|
+
|
|
92
|
+
```blocks
|
|
93
|
+
let lightsOn = 0
|
|
94
|
+
input.onSound(DetectedSound.Loud, function () {
|
|
95
|
+
if (lightsOn) {
|
|
96
|
+
basic.showLeds(`
|
|
97
|
+
# # # # #
|
|
98
|
+
# . . . #
|
|
99
|
+
# . . . #
|
|
100
|
+
# . . . #
|
|
101
|
+
# # # # #
|
|
102
|
+
`)
|
|
103
|
+
} else {
|
|
104
|
+
// @highlight
|
|
105
|
+
basic.clearScreen()
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 7. Setting the lightsOn variable
|
|
111
|
+
|
|
112
|
+
🎬 **Lights, camera, _action_** ✨
|
|
113
|
+
|
|
114
|
+
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.
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
► From ``||variables:Variables||``, locate ``||variables:set [lightsOn] to [0]||`` and snap it in at the **very top** of your ``||input:on [loud] sound||`` container.
|
|
119
|
+
|
|
120
|
+
► From the ``||logic:Logic||`` category, find the ``||logic:not <>||`` operator and use it to **replace the ``[0]``** in ``||variables:set [lightsOn] to [0]||``.
|
|
121
|
+
|
|
122
|
+
► From ``||variables:Variables||``, grab ``||variables:lightsOn||`` and snap it into the **empty part** of the ``||logic:not <>||`` operator.
|
|
123
|
+
|
|
124
|
+
```blocks
|
|
125
|
+
let lightsOn = false
|
|
126
|
+
input.onSound(DetectedSound.Loud, function () {
|
|
127
|
+
// @highlight
|
|
128
|
+
lightsOn = !(lightsOn)
|
|
129
|
+
if (lightsOn) {
|
|
130
|
+
basic.showLeds(`
|
|
131
|
+
# # # # #
|
|
132
|
+
# . . . #
|
|
133
|
+
# . . . #
|
|
134
|
+
# . . . #
|
|
135
|
+
# # # # #
|
|
136
|
+
`)
|
|
137
|
+
} else {
|
|
138
|
+
basic.clearScreen()
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 8. Testing in the simulator
|
|
144
|
+
|
|
145
|
+
💡 **Test what you've created** 💡
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
► Check out the simulator!
|
|
150
|
+
|
|
151
|
+
► Click on the pink slider bar beneath the microphone icon and drag it up and down.
|
|
152
|
+
💡 Right now, your @boardname@ thinks that anything above 128 is loud. Every time the sound goes > 128, your lights should switch on/off.
|
|
153
|
+
|
|
154
|
+
## 8. Set loud sound threshold
|
|
155
|
+
|
|
156
|
+
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 🔉🔊
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
► Click on the ``||input:Input||`` category. A new category should show up beneath it called ``||input:...more||``.
|
|
161
|
+
|
|
162
|
+
► From ``||input:...more||``, grab ``||input:set [loud] sound threshold to [128]||`` and snap it into your **empty** ``||basic: on start||`` container.
|
|
163
|
+
💡 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.
|
|
164
|
+
|
|
165
|
+
```blocks
|
|
166
|
+
// @highlight
|
|
167
|
+
input.setSoundThreshold(SoundThreshold.Loud, 150)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## 9. Testing, round 2
|
|
171
|
+
|
|
172
|
+
👏 **YOU DID IT!** 👏
|
|
173
|
+
|
|
174
|
+
Don't forget to test your code in the simulator!
|
|
175
|
+
|
|
176
|
+
If you have a new @boardname@ (the one with the **shiny gold** logo at the top), download this code and try it out!
|
|
177
|
+
|
|
178
|
+
```blocks
|
|
179
|
+
let lightsOn = false
|
|
180
|
+
input.onSound(DetectedSound.Loud, function () {
|
|
181
|
+
lightsOn = !(lightsOn)
|
|
182
|
+
if (lightsOn) {
|
|
183
|
+
basic.showLeds(`
|
|
184
|
+
# # # # #
|
|
185
|
+
# . . . #
|
|
186
|
+
# . . . #
|
|
187
|
+
# . . . #
|
|
188
|
+
# # # # #
|
|
189
|
+
`)
|
|
190
|
+
} else {
|
|
191
|
+
basic.clearScreen()
|
|
192
|
+
}
|
|
193
|
+
})
|
|
194
|
+
input.setSoundThreshold(SoundThreshold.Loud, 150)
|
|
195
|
+
```
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Countdown
|
|
2
|
+
|
|
3
|
+
## 1. Introduction @unplugged
|
|
4
|
+
|
|
5
|
+
🎇3...🎇2...🎇1...
|
|
6
|
+
🎆GO!🎆
|
|
7
|
+
|
|
8
|
+
Let's create a musical countdown using the new @boardname@ with sound!
|
|
9
|
+
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
## 2. Setting up the loop
|
|
13
|
+
|
|
14
|
+
➰ **All looped up** ➰
|
|
15
|
+
|
|
16
|
+
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.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
► From the ``||loops:Loops||`` category in your toolbox, find the ``||loops:for [index] from 0 to [4]||`` loop and add it to your ``||basic:on start||`` container.
|
|
21
|
+
|
|
22
|
+
► Change your loop to count from ``0`` to **``2``**.
|
|
23
|
+
💡 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!
|
|
24
|
+
|
|
25
|
+
```blocks
|
|
26
|
+
// @highlight
|
|
27
|
+
for (let index = 0; index <= 2; index++) {
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 3. Play music
|
|
33
|
+
|
|
34
|
+
🎵 **Musical loops** 🎵
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
► From ``||music:Music||``, grab ``||music:play tone [Middle C] for [1 beat]||`` and snap it into your empty ``for`` loop.
|
|
39
|
+
💡 Your simulator might start playing music. You can mute it if distracting.
|
|
40
|
+
|
|
41
|
+
► 1 beat is a little long. Use the **dropdown** to set the tone to play for ``||music:1/4 beat||``.
|
|
42
|
+
|
|
43
|
+
```blocks
|
|
44
|
+
for (let index = 0; index <= 2; index++) {
|
|
45
|
+
// @highlight
|
|
46
|
+
music.playTone(262, music.beat(BeatFraction.Quarter))
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 4. Showing a number
|
|
51
|
+
|
|
52
|
+
✨ **Razzle dazzle down** ✨
|
|
53
|
+
|
|
54
|
+
With every tone, we also want to **display** our countdown.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
► From ``||basic:Basic||``, find ``||basic:show number [0]||`` and snap it in at the **bottom** of your ``for`` loop.
|
|
59
|
+
|
|
60
|
+
► From your ``||loops:for [index] from 0 to [2]||`` loop condition, click and drag out the **red** ``||variables:index||`` variable.
|
|
61
|
+
|
|
62
|
+
► Use the ``||variables:index||`` that you dragged out to **replace** the ``0`` in ``||basic:show number [0]||``.
|
|
63
|
+
|
|
64
|
+
```blocks
|
|
65
|
+
for (let index = 0; index <= 2; index++) {
|
|
66
|
+
music.playTone(262, music.beat(BeatFraction.Quarter))
|
|
67
|
+
// @highlight
|
|
68
|
+
basic.showNumber(index)
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 5. Inverting the number
|
|
73
|
+
|
|
74
|
+
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.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
► From the ``||math:Math||`` category, snap ``||math:[0] - [0]||`` in to **replace** ``||variables:index||`` in your ``||basic:show number [index]||`` block.
|
|
79
|
+
💡 You should now have a greyed out ``index`` variable in your workspace. We'll use that in the next step.
|
|
80
|
+
|
|
81
|
+
► Pick up the greyed out ``||variables:index||`` variable and snap it in to the **right side** of your ``||math:[0] - [0]||`` operator.
|
|
82
|
+
💡 Can't find ``||variables:index||``? Try moving your ``||basic:on start||`` container to see if ``||variables: index||`` is hiding behind it!
|
|
83
|
+
|
|
84
|
+
► Set the **left side** of your ``||math:[0]-[index]||`` operator to **``3``**.
|
|
85
|
+
💡 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**!
|
|
86
|
+
|
|
87
|
+
```blocks
|
|
88
|
+
for (let index = 0; index <= 2; index++) {
|
|
89
|
+
music.playTone(262, music.beat(BeatFraction.Quarter))
|
|
90
|
+
// @highlight
|
|
91
|
+
basic.showNumber(3 - index)
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## 6. Printing "GO!"
|
|
96
|
+
|
|
97
|
+
🏁 **You had me at "GO!"** 🏁
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
► From ``||basic:Basic||``, grab ``||basic:show string ["Hello!"]||`` and snap it into the **very bottom** of your ``||basic:on start||`` container.
|
|
102
|
+
|
|
103
|
+
► Replace ``Hello!`` with the word ``GO!``
|
|
104
|
+
|
|
105
|
+
```blocks
|
|
106
|
+
for (let index = 0; index <= 2; index++) {
|
|
107
|
+
music.playTone(262, music.beat(BeatFraction.Quarter))
|
|
108
|
+
basic.showNumber(3 - index)
|
|
109
|
+
}
|
|
110
|
+
// @highlight
|
|
111
|
+
basic.showString("GO!")
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## 7. Adding a "GO!" noise
|
|
115
|
+
|
|
116
|
+
🏇 **And we're off!** 🏇
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
► From the ``||music:Music||`` category, grab ``||music:play tone [Middle C] for [1 beat]||`` and place it **above** your ``||basic:show string ["GO!"]||`` block and **below** your ``||loops:for||`` loop.
|
|
121
|
+
💡 This will let your @boardname@ play the sound and show ``GO!`` at the same time.
|
|
122
|
+
|
|
123
|
+
► Set the ``||music:tone||`` to be ``Middle G``.
|
|
124
|
+
💡 ``Middle G`` is also tone ``392``.
|
|
125
|
+
|
|
126
|
+
```blocks
|
|
127
|
+
for (let index = 0; index <= 2; index++) {
|
|
128
|
+
music.playTone(262, music.beat(BeatFraction.Quarter))
|
|
129
|
+
basic.showNumber(3 - index)
|
|
130
|
+
}
|
|
131
|
+
// @highlight
|
|
132
|
+
music.playTone(392, music.beat(BeatFraction.Whole))
|
|
133
|
+
basic.showString("GO!")
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## 8. Testing in the simulator
|
|
137
|
+
|
|
138
|
+
🚦 **Test what you've created** 🚦
|
|
139
|
+
|
|
140
|
+
Make sure your speakers are on and check out the simulator!
|
|
141
|
+
|
|
142
|
+
If you have a @boardname@ with sound (the one with the **shiny gold** logo at the top), no need to plug in an external speaker - just download this code and try it out!
|
|
143
|
+
|
|
144
|
+
```blocks
|
|
145
|
+
for (let index = 0; index <= 2; index++) {
|
|
146
|
+
music.playTone(262, music.beat(BeatFraction.Quarter))
|
|
147
|
+
basic.showNumber(3 - index)
|
|
148
|
+
}
|
|
149
|
+
music.playTone(392, music.beat(BeatFraction.Whole))
|
|
150
|
+
basic.showString("GO!")
|
|
151
|
+
```
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# Morse Chat
|
|
2
|
+
|
|
3
|
+
## 1. Introducing Sky @unplugged
|
|
4
|
+
|
|
5
|
+
🐷 Meet Sky, the pig! Sky can only communicate using [__*morse code*__](#morsecode "an alphabet composed of dots (short signals) and dashes (long signals)").
|
|
6
|
+
|
|
7
|
+
Luckily, you can use your @boardname@ with sound to talk to Sky 👋
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
## 2. Setup
|
|
12
|
+
|
|
13
|
+
⚙️ **Communication works best when set up properly** ⚙️
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
► From the ``||input:Input||`` category in the toolbox, drag an ``||input:on logo [pressed]||`` container into to your workspace.
|
|
18
|
+
|
|
19
|
+
► From the ``||radio:Radio||`` category, get ``||radio:radio send number [0]||`` and snap it into your empty ``||input:on logo [pressed]||`` container.
|
|
20
|
+
|
|
21
|
+
```blocks
|
|
22
|
+
input.onLogoEvent(TouchButtonEvent.Pressed, function () {
|
|
23
|
+
radio.sendNumber(0)
|
|
24
|
+
})
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 3. Sending different messages pt. 1
|
|
28
|
+
|
|
29
|
+
💬 **Sending Sky two _different_ messages** 💬
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
► From ``||input:Input||``, grab **another** ``||input:on logo [pressed]||`` container and add it to your workspace.
|
|
34
|
+
💡 This container is greyed out because it matches another. Let's change that!
|
|
35
|
+
|
|
36
|
+
► On the greyed-out ``||input:on logo [pressed]||`` container, click on the **``pressed``** dropdown and set it to ``||input:long pressed||``.
|
|
37
|
+
|
|
38
|
+
```blocks
|
|
39
|
+
// @highlight
|
|
40
|
+
input.onLogoEvent(TouchButtonEvent.LongPressed, function () {
|
|
41
|
+
})
|
|
42
|
+
input.onLogoEvent(TouchButtonEvent.Pressed, function () {
|
|
43
|
+
radio.sendNumber(0)
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 4. Sending different messages pt. 2
|
|
48
|
+
|
|
49
|
+
► From the ``||radio:Radio||`` category, get a ``||radio:radio send number [0]||`` block and snap it into your **empty** ``||input:on logo [long pressed]||`` container.
|
|
50
|
+
|
|
51
|
+
► Set the number to be ``1``.
|
|
52
|
+
|
|
53
|
+
```blocks
|
|
54
|
+
input.onLogoEvent(TouchButtonEvent.LongPressed, function () {
|
|
55
|
+
// @highlight
|
|
56
|
+
radio.sendNumber(1)
|
|
57
|
+
})
|
|
58
|
+
input.onLogoEvent(TouchButtonEvent.Pressed, function () {
|
|
59
|
+
radio.sendNumber(0)
|
|
60
|
+
})
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## 5. Receiving different messages
|
|
64
|
+
|
|
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
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
► From ``||radio:Radio||``, find the ``||radio:on radio received [receivedNumber]||`` container and add it to your workspace.
|
|
70
|
+
|
|
71
|
+
► From ``||logic:Logic||``, grab an ``||logic:if <true> then / else||`` statement and snap it into your **new** ``||radio:on radio received [receivedNumber]||`` container.
|
|
72
|
+
|
|
73
|
+
► Go back to the ``||logic:Logic||`` category, grab ``||logic:<[0] [=] [0]>||``, and click it in to **replace** the ``||logic:<true>||`` argument in your ``||logic:if <true> then / else||`` statement.
|
|
74
|
+
|
|
75
|
+
```blocks
|
|
76
|
+
radio.onReceivedNumber(function (receivedNumber) {
|
|
77
|
+
// @highlight
|
|
78
|
+
if (0 == 0) {
|
|
79
|
+
|
|
80
|
+
} else {
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## 6. Conditioning on the input
|
|
87
|
+
|
|
88
|
+
► From your ``||radio:on radio received [receivedNumber]||`` container, grab the **``receivedNumber``** input and drag out a copy.
|
|
89
|
+
|
|
90
|
+
► Use your copy of **``receivedNumber``** to replace the ``[0]`` on the **left side** of ``||logic:<[0] [=] [0]>||``.
|
|
91
|
+
|
|
92
|
+
```blocks
|
|
93
|
+
radio.onReceivedNumber(function (receivedNumber) {
|
|
94
|
+
// @highlight
|
|
95
|
+
if (receivedNumber == 0) {
|
|
96
|
+
|
|
97
|
+
} else {
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## 7. Displaying a message pt. 1
|
|
104
|
+
|
|
105
|
+
📃 **Dashing through the lights** 📃
|
|
106
|
+
|
|
107
|
+
► 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:if then / else||`` statement.
|
|
108
|
+
|
|
109
|
+
► Turn on 3 LEDs in a row to be a dash: -
|
|
110
|
+
|
|
111
|
+
```blocks
|
|
112
|
+
radio.onReceivedNumber(function (receivedNumber) {
|
|
113
|
+
if (receivedNumber == 0) {
|
|
114
|
+
} else {
|
|
115
|
+
// @highlight
|
|
116
|
+
basic.showLeds(`
|
|
117
|
+
. . . . .
|
|
118
|
+
. . . . .
|
|
119
|
+
. # # # .
|
|
120
|
+
. . . . .
|
|
121
|
+
. . . . .
|
|
122
|
+
`)
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## 8. Playing a sound pt. 1
|
|
128
|
+
|
|
129
|
+
🎵 **Adding sound** 🎵
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
► From the ``||music:Music||`` category, grab a ``||music:play tone [Middle C] for [1 beat]||`` block and snap it at the **end** of the **bottom container** in your ``||logic:if then / else||`` statement.
|
|
134
|
+
|
|
135
|
+
```blocks
|
|
136
|
+
radio.onReceivedNumber(function (receivedNumber) {
|
|
137
|
+
if (receivedNumber == 0) {
|
|
138
|
+
} else {
|
|
139
|
+
basic.showLeds(`
|
|
140
|
+
. . . . .
|
|
141
|
+
. . . . .
|
|
142
|
+
. # # # .
|
|
143
|
+
. . . . .
|
|
144
|
+
. . . . .
|
|
145
|
+
`)
|
|
146
|
+
// @highlight
|
|
147
|
+
music.playTone(262, music.beat(BeatFraction.Whole))
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## 9. Displaying a message pt. 2
|
|
153
|
+
|
|
154
|
+
⚫ **Dot dot dot** ⚫
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
► 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:if then / else||`` statement.
|
|
159
|
+
|
|
160
|
+
► Turn on a single LED to make a dot: .
|
|
161
|
+
|
|
162
|
+
```blocks
|
|
163
|
+
radio.onReceivedNumber(function (receivedNumber) {
|
|
164
|
+
if (receivedNumber == 0) {
|
|
165
|
+
// @highlight
|
|
166
|
+
basic.showLeds(`
|
|
167
|
+
. . . . .
|
|
168
|
+
. . . . .
|
|
169
|
+
. . # . .
|
|
170
|
+
. . . . .
|
|
171
|
+
. . . . .
|
|
172
|
+
`)
|
|
173
|
+
} else {
|
|
174
|
+
basic.showLeds(`
|
|
175
|
+
. . . . .
|
|
176
|
+
. . . . .
|
|
177
|
+
. # # # .
|
|
178
|
+
. . . . .
|
|
179
|
+
. . . . .
|
|
180
|
+
`)
|
|
181
|
+
music.playTone(262, music.beat(BeatFraction.Whole))
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## 10. Playing a sound pt. 2
|
|
187
|
+
|
|
188
|
+
► From the ``||music:Music||`` category, grab ``||music:play tone [Middle C] for [1 beat]||`` and snap it in at the **end** of the **top container** in your ``||logic:if then / else||`` statement.
|
|
189
|
+
|
|
190
|
+
► Dots are shorter than dashes! Set the tone to play for ``1/4 beat``.
|
|
191
|
+
|
|
192
|
+
```blocks
|
|
193
|
+
radio.onReceivedNumber(function (receivedNumber) {
|
|
194
|
+
if (receivedNumber == 0) {
|
|
195
|
+
basic.showLeds(`
|
|
196
|
+
. . . . .
|
|
197
|
+
. . . . .
|
|
198
|
+
. . # . .
|
|
199
|
+
. . . . .
|
|
200
|
+
. . . . .
|
|
201
|
+
`)
|
|
202
|
+
// @highlight
|
|
203
|
+
music.playTone(262, music.beat(BeatFraction.Quarter))
|
|
204
|
+
} else {
|
|
205
|
+
basic.showLeds(`
|
|
206
|
+
. . . . .
|
|
207
|
+
. . . . .
|
|
208
|
+
. # # # .
|
|
209
|
+
. . . . .
|
|
210
|
+
. . . . .
|
|
211
|
+
`)
|
|
212
|
+
music.playTone(262, music.beat(BeatFraction.Whole))
|
|
213
|
+
}
|
|
214
|
+
})
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## 11. Clearing the screens
|
|
218
|
+
|
|
219
|
+
🗨️ **Clear the lights once the messages are sent** 🗨️
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
► From ``||basic:Basic||``, find ``||basic:clear screen||`` and snap it in at the **very bottom** of your ``||radio:on radio received [receivedNumber]||`` container.
|
|
224
|
+
|
|
225
|
+
```blocks
|
|
226
|
+
radio.onReceivedNumber(function (receivedNumber) {
|
|
227
|
+
if (receivedNumber == 0) {
|
|
228
|
+
basic.showLeds(`
|
|
229
|
+
. . . . .
|
|
230
|
+
. . . . .
|
|
231
|
+
. . # . .
|
|
232
|
+
. . . . .
|
|
233
|
+
. . . . .
|
|
234
|
+
`)
|
|
235
|
+
music.playTone(262, music.beat(BeatFraction.Quarter))
|
|
236
|
+
} else {
|
|
237
|
+
basic.showLeds(`
|
|
238
|
+
. . . . .
|
|
239
|
+
. . . . .
|
|
240
|
+
. # # # .
|
|
241
|
+
. . . . .
|
|
242
|
+
. . . . .
|
|
243
|
+
`)
|
|
244
|
+
music.playTone(262, music.beat(BeatFraction.Whole))
|
|
245
|
+
}
|
|
246
|
+
// @highlight
|
|
247
|
+
basic.clearScreen()
|
|
248
|
+
})
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## 12. Testing in the simulator
|
|
252
|
+
|
|
253
|
+
🐷 **Test what you've created** 💬
|
|
254
|
+
|
|
255
|
+
Remember to turn your sound on!
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
► Touch the gold logo at the top of your @boardname@ (it looks like a pig snout 🐽) on the simulator. You'll notice that a second @boardname@ appears.
|
|
260
|
+
💡 If your screen is too small, you might not be able to see it.
|
|
261
|
+
|
|
262
|
+
► Touch the 🐽 again to send messages to Sky 🐖
|
|
263
|
+
**Press** to send a dot.
|
|
264
|
+
**Long press** (count to 3!) to send a dash.
|
|
265
|
+
|
|
266
|
+
► If you have multiple @boardname@s with sound (they have **shiny gold** logos at the top), download this code and try it out!
|
|
267
|
+
|
|
268
|
+
```blocks
|
|
269
|
+
radio.onReceivedNumber(function (receivedNumber) {
|
|
270
|
+
if (receivedNumber == 0) {
|
|
271
|
+
basic.showLeds(`
|
|
272
|
+
. . . . .
|
|
273
|
+
. . . . .
|
|
274
|
+
. . # . .
|
|
275
|
+
. . . . .
|
|
276
|
+
. . . . .
|
|
277
|
+
`)
|
|
278
|
+
music.playTone(262, music.beat(BeatFraction.Quarter))
|
|
279
|
+
} else {
|
|
280
|
+
basic.showLeds(`
|
|
281
|
+
. . . . .
|
|
282
|
+
. . . . .
|
|
283
|
+
. # # # .
|
|
284
|
+
. . . . .
|
|
285
|
+
. . . . .
|
|
286
|
+
`)
|
|
287
|
+
music.playTone(262, music.beat(BeatFraction.Whole))
|
|
288
|
+
}
|
|
289
|
+
basic.clearScreen()
|
|
290
|
+
})
|
|
291
|
+
input.onLogoEvent(TouchButtonEvent.LongPressed, function () {
|
|
292
|
+
radio.sendNumber(1)
|
|
293
|
+
})
|
|
294
|
+
input.onLogoEvent(TouchButtonEvent.Pressed, function () {
|
|
295
|
+
radio.sendNumber(0)
|
|
296
|
+
})
|
|
297
|
+
```
|