pxt-microbit 6.1.4 → 6.1.6
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/hexcache/2316606247833679614224bfef7f9d1115124bfe4d83e3c80bd15ce4be60db95.hex +20345 -0
- package/built/hexcache/{56661ceac4d8678e416df6f0cb117457b277232c45f0a578a9298d26f8eaba35.hex → 264c0c5bdecf5845031b4b2a92959e799ecb81c940114f796158472702460816.hex} +10524 -10513
- package/built/target.js +1 -1
- package/built/target.json +1 -1
- package/built/targetlight.json +1 -1
- package/built/web/rtlsemantic.css +1 -1
- package/built/web/semantic.css +1 -1
- package/docs/device/usb/webusb.md +55 -31
- package/docs/homepage-content.md +20 -0
- package/docs/projects/dice.md +12 -18
- package/docs/projects/flashing-heart.md +12 -8
- package/docs/projects/love-meter.md +17 -10
- package/docs/projects/micro-chat.md +38 -17
- package/docs/projects/name-tag.md +9 -14
- package/docs/projects/rock-paper-scissors.md +136 -81
- package/docs/projects/smiley-buttons.md +24 -46
- package/docs/projects/spy/dice.md +17 -17
- package/docs/projects/spy/flashing-heart.md +12 -27
- package/docs/projects/spy/love-meter.md +35 -17
- package/docs/projects/spy/micro-chat.md +35 -22
- package/docs/projects/spy/name-tag.md +14 -23
- package/docs/projects/spy/rock-paper-scissors.md +27 -77
- package/docs/projects/spy/smiley-buttons.md +20 -26
- package/docs/projects/step-counter.md +51 -30
- package/docs/tutorials.md +6 -6
- package/package.json +2 -2
- package/pxtarget.json +1 -1
- package/targetconfig.json +3 -2
- package/built/hexcache/02e118276d7ad61fd1e7913a87f10d8ffee34a65b883e7b8efce291712f45092.hex +0 -20334
|
@@ -4,172 +4,227 @@
|
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Turn your micro:bit into a **Rock Paper Scissors** game that you can play with your friends!
|
|
8
8
|
|
|
9
|
-
## {Step 1
|
|
9
|
+
## {Step 1}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
First we need to make a variable to keep track of whether we have a Rock, Paper or Scissors in our hand. A variable is a container for storing values. Click on the ``||variables:Variables||`` category in the Toolbox. Click on the **Make a Variable** button. Give your new variable the name "hand" and click Ok.
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
## {Step 2}
|
|
16
|
+
|
|
17
|
+
Click on the ``||variables:Variables||`` category in the Toolbox again. You'll notice that there are some new blocks that have appeared. Drag a ``||variables:set hand||`` block into the ``||input:on shake||`` block. We'll start our Rock Paper Scissors game when we shake 👋 our micro:bit.
|
|
12
18
|
|
|
13
19
|
```blocks
|
|
20
|
+
let hand = 0;
|
|
14
21
|
input.onGesture(Gesture.Shake, function() {
|
|
15
|
-
|
|
22
|
+
hand = 0
|
|
16
23
|
})
|
|
17
24
|
```
|
|
18
25
|
|
|
19
|
-
## {Step
|
|
26
|
+
## {Step 3}
|
|
20
27
|
|
|
21
|
-
|
|
28
|
+
Click on the ``||math:Math||`` category in the Toolbox. Drag a ``||math:pick random||`` block and drop it into the ``||variables:set hand||`` block replacing the number 0. Now when we shake our micro:bit, the variable hand will contain a random number between 1 and 3.
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
```blocks
|
|
31
|
+
let hand = 0;
|
|
32
|
+
input.onGesture(Gesture.Shake, function() {
|
|
33
|
+
hand = randint(1, 3)
|
|
34
|
+
})
|
|
35
|
+
```
|
|
24
36
|
|
|
25
|
-
## {Step
|
|
37
|
+
## {Step 4}
|
|
26
38
|
|
|
27
|
-
|
|
39
|
+
Click on the ``||logic:Logic||`` category in the Toolbox. Drag the ``||logic:if true then else||`` block out to the workspace and drop it into the ``||input:on shake||`` block under the ``||variables:set hand||`` block.
|
|
28
40
|
|
|
29
41
|
```blocks
|
|
30
42
|
let hand = 0;
|
|
31
43
|
input.onGesture(Gesture.Shake, function() {
|
|
32
44
|
hand = randint(1, 3)
|
|
45
|
+
if (true) {
|
|
46
|
+
|
|
47
|
+
} else {
|
|
48
|
+
|
|
49
|
+
}
|
|
33
50
|
})
|
|
34
51
|
```
|
|
35
52
|
|
|
36
|
-
|
|
53
|
+
## {Step 5}
|
|
37
54
|
|
|
38
|
-
|
|
55
|
+
From the ``||logic:Logic||`` category, drag a ``||logic:0 = 0||`` comparison block and drop it into the ``||logic:if true then else||`` block replacing **true**.
|
|
39
56
|
|
|
40
|
-
|
|
57
|
+
```blocks
|
|
58
|
+
let hand = 0;
|
|
59
|
+
input.onGesture(Gesture.Shake, function() {
|
|
60
|
+
hand = randint(1, 3)
|
|
61
|
+
if (0 == 0) {
|
|
62
|
+
|
|
63
|
+
} else {
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
```
|
|
41
68
|
|
|
42
|
-
|
|
69
|
+
## {Step 6}
|
|
70
|
+
|
|
71
|
+
Click on the ``||variables:Variables||`` category in the Toolbox. Drag a ``||variables:hand||`` block out and drop it into the ``||logic:0 = 0||`` comparison block replacing the first **0**. Click on the second 0 in the comparison block and change to **1**.
|
|
43
72
|
|
|
44
73
|
```blocks
|
|
45
74
|
let hand = 0;
|
|
46
75
|
input.onGesture(Gesture.Shake, function() {
|
|
47
76
|
hand = randint(1, 3)
|
|
48
77
|
if (hand == 1) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
# . . . #
|
|
53
|
-
# . . . #
|
|
54
|
-
# # # # #
|
|
55
|
-
`)
|
|
78
|
+
|
|
79
|
+
} else {
|
|
80
|
+
|
|
56
81
|
}
|
|
57
82
|
})
|
|
58
83
|
```
|
|
59
84
|
|
|
60
|
-
## {Step
|
|
85
|
+
## {Step 7}
|
|
61
86
|
|
|
62
|
-
Click on the
|
|
87
|
+
Click on the ``||basic:Basic||`` category in the Toolbox. Drag a ``||basic:show icon||`` block out and drop it under ``||logic:if hand = 1 then||``. In the ``||basic:show icon||`` block, click on the Heart icon and instead select the small square icon to represent a 💎 Rock.
|
|
63
88
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
89
|
+
```blocks
|
|
90
|
+
let hand = 0;
|
|
91
|
+
input.onGesture(Gesture.Shake, function() {
|
|
92
|
+
hand = randint(1, 3)
|
|
93
|
+
if (hand == 1) {
|
|
94
|
+
basic.showIcon(IconNames.SmallSquare)
|
|
95
|
+
} else {
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
```
|
|
67
100
|
|
|
68
|
-
|
|
101
|
+
## {Step 8}
|
|
69
102
|
|
|
70
|
-
|
|
103
|
+
At the bottom of the ``||logic:if then else||`` block, click on the plus **'+'** sign. This will expand the code to include an ``||logic:else if||`` clause.
|
|
71
104
|
|
|
72
105
|
```blocks
|
|
73
106
|
let hand = 0;
|
|
74
107
|
input.onGesture(Gesture.Shake, function() {
|
|
75
108
|
hand = randint(1, 3)
|
|
76
109
|
if (hand == 1) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
# . . . #
|
|
81
|
-
# . . . #
|
|
82
|
-
# # # # #
|
|
83
|
-
`)
|
|
110
|
+
basic.showIcon(IconNames.SmallSquare)
|
|
111
|
+
} else if (false) {
|
|
112
|
+
|
|
84
113
|
} else {
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## {Step 9}
|
|
120
|
+
|
|
121
|
+
From the ``||logic:Logic||`` category, drag a ``||logic:0 = 0||`` comparison block and drop it into the open space next to the ``||logic:else if||`` clause.
|
|
85
122
|
|
|
123
|
+
```blocks
|
|
124
|
+
let hand = 0;
|
|
125
|
+
input.onGesture(Gesture.Shake, function() {
|
|
126
|
+
hand = randint(1, 3)
|
|
127
|
+
if (hand == 1) {
|
|
128
|
+
basic.showIcon(IconNames.SmallSquare)
|
|
129
|
+
} else if (0 == 0) {
|
|
130
|
+
|
|
131
|
+
} else {
|
|
132
|
+
|
|
86
133
|
}
|
|
87
134
|
})
|
|
88
135
|
```
|
|
89
136
|
|
|
90
|
-
## {Step
|
|
137
|
+
## {Step 10}
|
|
91
138
|
|
|
92
|
-
|
|
139
|
+
From the ``||variables:Variables||`` category, drag a ``||variables:hand||`` block and drop it into the ``||logic:0 = 0||`` comparison block replacing the first **0**. Click on the second 0 in the comparison block and change to **2**.
|
|
93
140
|
|
|
94
141
|
```blocks
|
|
95
142
|
let hand = 0;
|
|
96
143
|
input.onGesture(Gesture.Shake, function() {
|
|
97
144
|
hand = randint(1, 3)
|
|
98
145
|
if (hand == 1) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
# . . . #
|
|
103
|
-
# . . . #
|
|
104
|
-
# # # # #
|
|
105
|
-
`)
|
|
146
|
+
basic.showIcon(IconNames.SmallSquare)
|
|
147
|
+
} else if (hand == 2) {
|
|
148
|
+
|
|
106
149
|
} else {
|
|
107
|
-
|
|
108
|
-
# # . . #
|
|
109
|
-
# # . # .
|
|
110
|
-
. . # . .
|
|
111
|
-
# # . # .
|
|
112
|
-
# # . . #
|
|
113
|
-
`)
|
|
150
|
+
|
|
114
151
|
}
|
|
115
152
|
})
|
|
116
153
|
```
|
|
117
154
|
|
|
118
|
-
## {Step
|
|
155
|
+
## {Step 11}
|
|
119
156
|
|
|
120
|
-
|
|
157
|
+
From the ``||basic:Basic||`` category, drag a ``||basic:show icon||`` block out and drop it under ``||logic:else if hand = 2 then||``. In the ``||basic:show icon||`` block, click on the Heart icon and instead select the large square icon to represent 📃 Paper.
|
|
121
158
|
|
|
122
|
-
|
|
159
|
+
```blocks
|
|
160
|
+
let hand = 0;
|
|
161
|
+
input.onGesture(Gesture.Shake, function() {
|
|
162
|
+
hand = randint(1, 3)
|
|
163
|
+
if (hand == 1) {
|
|
164
|
+
basic.showIcon(IconNames.SmallSquare)
|
|
165
|
+
} else if (hand == 2) {
|
|
166
|
+
basic.showIcon(IconNames.Square)
|
|
167
|
+
} else {
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
```
|
|
123
172
|
|
|
124
|
-
## {Step
|
|
173
|
+
## {Step 12}
|
|
125
174
|
|
|
126
|
-
|
|
175
|
+
Now let's deal with the last condition - if our hand variable isn't holding a 1 (Rock) or a 2 (Paper), then it must be 3 (✀ Scissors)! From the ``||basic:Basic||`` category, drag another ``||basic:show icon||`` block out and drop it into the last opening under the ``||logic:else||``. In the ``||basic:show icon||`` block, click on the Heart icon and select the Scissors icon.
|
|
127
176
|
|
|
128
177
|
```blocks
|
|
129
178
|
let hand = 0;
|
|
130
179
|
input.onGesture(Gesture.Shake, function() {
|
|
131
180
|
hand = randint(1, 3)
|
|
132
181
|
if (hand == 1) {
|
|
133
|
-
|
|
134
|
-
# # # # #
|
|
135
|
-
# . . . #
|
|
136
|
-
# . . . #
|
|
137
|
-
# . . . #
|
|
138
|
-
# # # # #
|
|
139
|
-
`)
|
|
182
|
+
basic.showIcon(IconNames.SmallSquare)
|
|
140
183
|
} else if (hand == 2) {
|
|
141
|
-
|
|
142
|
-
. . . . .
|
|
143
|
-
. # # # .
|
|
144
|
-
. # # # .
|
|
145
|
-
. # # # .
|
|
146
|
-
. . . . .
|
|
147
|
-
`)
|
|
184
|
+
basic.showIcon(IconNames.Square)
|
|
148
185
|
} else {
|
|
149
|
-
|
|
150
|
-
# # . . #
|
|
151
|
-
# # . # .
|
|
152
|
-
. . # . .
|
|
153
|
-
# # . # .
|
|
154
|
-
# # . . #
|
|
155
|
-
`)
|
|
186
|
+
basic.showIcon(IconNames.Scissors)
|
|
156
187
|
}
|
|
157
188
|
})
|
|
158
189
|
```
|
|
159
190
|
|
|
160
|
-
## {Step
|
|
191
|
+
## {Step 13}
|
|
161
192
|
|
|
162
|
-
|
|
193
|
+
Let's test your code! Press the white **SHAKE** button on the micro:bit on-screen simulator, or move your cursor quickly back and forth over the simulator. Do you see the icons for rock, paper and scissors randomly appear? ⭐ Great job! ⭐
|
|
163
194
|
|
|
164
195
|

|
|
165
196
|
|
|
166
|
-
## {Step
|
|
197
|
+
## {Step 14}
|
|
167
198
|
|
|
168
|
-
If you have a @boardname
|
|
169
|
-
onto your @boardname@. Your game is ready! Gather your friends and play Rock Paper Scissors!
|
|
199
|
+
If you have a @boardname@ device, connect it to your computer and click the ``|Download|`` button. Follow the instructions to transfer your code onto the @boardname@. Once your code has been downloaded, attach your micro:bit to a battery pack and challenge another micro:bit or a human to a game of Rock, Paper, Scissors!
|
|
170
200
|
|
|
171
201
|

|
|
172
202
|
|
|
203
|
+
## {Step 15}
|
|
204
|
+
|
|
205
|
+
Go further - Try adding 🎵 Music 🎵 blocks to your Rock Paper Scissors game for different sound effects. Note that some Music blocks may require a micro:bit v2 device to play.
|
|
206
|
+
|
|
207
|
+
```blocks
|
|
208
|
+
let hand = 0
|
|
209
|
+
input.onGesture(Gesture.Shake, function () {
|
|
210
|
+
hand = randint(1, 3)
|
|
211
|
+
if (hand == 1) {
|
|
212
|
+
basic.showIcon(IconNames.SmallSquare)
|
|
213
|
+
music.play(music.builtinPlayableSoundEffect(soundExpression.giggle), music.PlaybackMode.UntilDone)
|
|
214
|
+
} else if (hand == 2) {
|
|
215
|
+
basic.showIcon(IconNames.Square)
|
|
216
|
+
music.play(music.tonePlayable(262, music.beat(BeatFraction.Whole)), music.PlaybackMode.UntilDone)
|
|
217
|
+
} else {
|
|
218
|
+
basic.showIcon(IconNames.Scissors)
|
|
219
|
+
music.play(music.createSoundExpression(WaveShape.Square, 1600, 1, 255, 0, 300, SoundExpressionEffect.None, InterpolationCurve.Curve), music.PlaybackMode.UntilDone)
|
|
220
|
+
}
|
|
221
|
+
})
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
```blockconfig.global
|
|
225
|
+
randint(1, 3)
|
|
226
|
+
```
|
|
227
|
+
|
|
173
228
|
```template
|
|
174
229
|
input.onGesture(Gesture.Shake, function() {})
|
|
175
230
|
```
|
|
@@ -1,83 +1,61 @@
|
|
|
1
1
|
# Smiley Buttons
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Code a micro:bit emoji! @unplugged
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
(Want to learn how the buttons works? [Watch this video](https://youtu.be/t_Qujjd_38o)).
|
|
5
|
+
Program the buttons on the @boardname@ to show a happy 😀 or sad face 🙁
|
|
7
6
|
|
|
8
7
|

|
|
9
8
|
|
|
10
9
|
## {Step 1}
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
Let's show a happy face when we press button **A**.
|
|
12
|
+
Click on the ``||basic:Basic||`` category in the Toolbox. Drag a ``||basic:show icon||`` block into the ``||input:on button A pressed||`` block.
|
|
13
|
+
In the ``||basic:show icon||`` block, click on the Heart icon to open the menu. Select a Happy Face icon.
|
|
13
14
|
|
|
14
15
|
```blocks
|
|
15
16
|
input.onButtonPressed(Button.A, function() {
|
|
17
|
+
basic.showIcon(IconNames.Happy)
|
|
16
18
|
})
|
|
17
19
|
```
|
|
18
20
|
|
|
19
21
|
## {Step 2}
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
```blocks
|
|
24
|
-
input.onButtonPressed(Button.A, function() {
|
|
25
|
-
basic.showLeds(`
|
|
26
|
-
# # . # #
|
|
27
|
-
# # . # #
|
|
28
|
-
. . . . .
|
|
29
|
-
# . . . #
|
|
30
|
-
. # # # .`
|
|
31
|
-
)
|
|
32
|
-
})
|
|
33
|
-
```
|
|
23
|
+
In the @boardname@ simulator on the screen, press the **A** button. Do you see a happy face? ⭐ Great job! ⭐
|
|
34
24
|
|
|
35
25
|
## {Step 3}
|
|
36
26
|
|
|
37
|
-
|
|
27
|
+
Now let's show a sad face when we press button **B**.
|
|
28
|
+
Click on the ``||input:Input||`` category in the Toolbox.
|
|
29
|
+
Drag another ``||input:on button A pressed||`` block onto the coding workspace (you can place this anywhere).
|
|
30
|
+
Click on the **A** button drop-down menu, and select **B**.
|
|
38
31
|
|
|
39
32
|
```blocks
|
|
40
|
-
input.onButtonPressed(Button.B, function() {
|
|
41
|
-
basic.showLeds(`
|
|
42
|
-
# # . # #
|
|
43
|
-
# # . # #
|
|
44
|
-
. . . . .
|
|
45
|
-
. # # # .
|
|
46
|
-
# . . . #`
|
|
47
|
-
);
|
|
48
|
-
});
|
|
33
|
+
input.onButtonPressed(Button.B, function() {})
|
|
49
34
|
```
|
|
50
35
|
|
|
51
36
|
## {Step 4}
|
|
52
37
|
|
|
53
|
-
|
|
38
|
+
From the ``||basic:Basic||`` category, drag another ``||basic:show icon||`` block into the ``||input:on button B pressed||`` block.
|
|
39
|
+
In this ``||basic:show icon||`` block, click on the Heart icon to open the menu.
|
|
40
|
+
Select a Sad Face icon.
|
|
54
41
|
|
|
55
42
|
```blocks
|
|
56
|
-
input.onButtonPressed(Button.
|
|
57
|
-
basic.
|
|
58
|
-
. . . . .
|
|
59
|
-
# . # . .
|
|
60
|
-
. . . . .
|
|
61
|
-
# . . . #
|
|
62
|
-
. # # # .
|
|
63
|
-
`)
|
|
64
|
-
basic.showLeds(`
|
|
65
|
-
. . . . .
|
|
66
|
-
. . # . #
|
|
67
|
-
. . . . .
|
|
68
|
-
# . . . #
|
|
69
|
-
. # # # .
|
|
70
|
-
`)
|
|
43
|
+
input.onButtonPressed(Button.B, function() {
|
|
44
|
+
basic.showIcon(IconNames.Sad)
|
|
71
45
|
})
|
|
72
46
|
```
|
|
73
|
-
|
|
74
47
|
## {Step 5}
|
|
75
48
|
|
|
76
|
-
|
|
49
|
+
In the @boardname@ simulator on the screen, press the **B** button. Do you see a sad face? ⭐ Great job! ⭐
|
|
77
50
|
|
|
78
51
|
## {Step 6}
|
|
79
52
|
|
|
80
|
-
|
|
53
|
+
If you have a @boardname@ device, connect it to your computer and click the ``|Download|`` button. Follow the instructions to transfer your code onto the @boardname@. Try pressing the **A** and **B** buttons on the micro:bit to see your happy 😀 and sad 🙁 emojis!
|
|
54
|
+
|
|
55
|
+
## {Step 7}
|
|
56
|
+
|
|
57
|
+
Go further - try adding a secret emoji that appears when **A** and **B** buttons are pressed together!
|
|
58
|
+
Learn more about how the @boardname@ buttons work by watching [this video](https://youtu.be/t_Qujjd_38o).
|
|
81
59
|
|
|
82
60
|
```template
|
|
83
61
|
input.onButtonPressed(Button.A, function() {})
|
|
@@ -2,18 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
### @explicitHints true
|
|
4
4
|
|
|
5
|
-
## Introduction @unplugged
|
|
5
|
+
## {Introduction @unplugged}
|
|
6
6
|
|
|
7
|
-
Let's
|
|
8
|
-
(Want to learn how the accelerometer works? [Watch this video](https://youtu.be/byngcwjO51U)).
|
|
9
|
-
|
|
10
|
-
We need 3 pieces of code: one to detect a throw (shake), another to pick a random number, and then one to show the number.
|
|
7
|
+
Let's create some digital 🎲 dice 🎲 with our micro:bit!
|
|
11
8
|
|
|
12
9
|

|
|
13
10
|
|
|
14
|
-
## Step 1
|
|
11
|
+
## {Step 1}
|
|
15
12
|
|
|
16
|
-
Add an
|
|
13
|
+
We'll "roll" our dice when we shake the micro:bit. Add an ``||input:on gesture shake||`` function. Type the code below, or drag a code snippet from the ``||input:Input||`` Toolbox category.
|
|
17
14
|
|
|
18
15
|
```spy
|
|
19
16
|
input.onGesture(Gesture.Shake, function() {
|
|
@@ -21,9 +18,9 @@ input.onGesture(Gesture.Shake, function() {
|
|
|
21
18
|
})
|
|
22
19
|
```
|
|
23
20
|
|
|
24
|
-
## Step 2
|
|
21
|
+
## {Step 2}
|
|
25
22
|
|
|
26
|
-
|
|
23
|
+
Write some code to show a number in the ``||input:on shake||`` function, using the basic ``||basic:show number||`` function.
|
|
27
24
|
|
|
28
25
|
```spy
|
|
29
26
|
input.onGesture(Gesture.Shake, function() {
|
|
@@ -31,9 +28,9 @@ input.onGesture(Gesture.Shake, function() {
|
|
|
31
28
|
})
|
|
32
29
|
```
|
|
33
30
|
|
|
34
|
-
## Step 3
|
|
31
|
+
## {Step 3}
|
|
35
32
|
|
|
36
|
-
|
|
33
|
+
Instead of showing 0, use the ``||math:randint||`` function to show a random number between a minimum and maximum value.
|
|
37
34
|
|
|
38
35
|
```spy
|
|
39
36
|
input.onGesture(Gesture.Shake, function() {
|
|
@@ -41,9 +38,9 @@ input.onGesture(Gesture.Shake, function() {
|
|
|
41
38
|
})
|
|
42
39
|
```
|
|
43
40
|
|
|
44
|
-
## Step 4
|
|
41
|
+
## {Step 4}
|
|
45
42
|
|
|
46
|
-
A typical dice shows values from
|
|
43
|
+
A typical dice shows values from 1 to 6 dots. So, in the ``||math:randint||`` function, change the minimum value to **1** and the maximum value to **6**.
|
|
47
44
|
|
|
48
45
|
```spy
|
|
49
46
|
input.onGesture(Gesture.Shake, function() {
|
|
@@ -51,10 +48,13 @@ input.onGesture(Gesture.Shake, function() {
|
|
|
51
48
|
})
|
|
52
49
|
```
|
|
53
50
|
|
|
54
|
-
## Step 5
|
|
51
|
+
## {Step 5}
|
|
52
|
+
|
|
53
|
+
Press the white **SHAKE** button on the micro:bit simulator. Do you see random numbers between 1 and 6 appear? ⭐ Great job! ⭐
|
|
55
54
|
|
|
56
|
-
|
|
55
|
+
## {Step 6}
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
If you have a @boardname@ device, connect it to your computer and click the ``|Download|`` button. Follow the instructions to transfer your code onto the @boardname@. Once your code has been downloaded, attach your micro:bit to a battery pack and use it as digital 🎲 dice for your next boardgame!
|
|
59
58
|
|
|
60
|
-
|
|
59
|
+
## {Step 7}
|
|
60
|
+
Go further - Try adding some Music blocks to make a sound when you shake your dice, or use the micro:bit LED lights to show number values. Want to learn how the micro:bit motion detector or accelerometer works? [Watch this video](https://youtu.be/byngcwjO51U).
|
|
@@ -2,24 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
### @explicitHints true
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Code a Flashing Heart @unplugged
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
(Want to learn how lights work? [Watch this video](https://youtu.be/qqBmvHD5bCw)).
|
|
7
|
+
Code the lights on the micro:bit into a flashing heart animation! 💖
|
|
9
8
|
|
|
10
9
|

|
|
11
10
|
|
|
12
|
-
## Step 1 @fullscreen
|
|
11
|
+
## {Step 1 @fullscreen}
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
Use the basic ``||basic:show icon||`` function to display the **HEART** icon. Type the code below, or drag a code snippet from the ``||basic:Basic||`` Toolbox category.
|
|
15
14
|
|
|
16
15
|
```spy
|
|
17
16
|
basic.showIcon(IconNames.Heart)
|
|
18
17
|
```
|
|
19
18
|
|
|
20
|
-
## Step 2
|
|
19
|
+
## {Step 2}
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
Use the ``||basic:clear screen||`` function followed by the ``||basic:pause||`` function to turn off the lights for **500** milliseconds (or half a second).
|
|
23
22
|
|
|
24
23
|
```spy
|
|
25
24
|
basic.showIcon(IconNames.Heart)
|
|
@@ -27,9 +26,9 @@ basic.clearScreen()
|
|
|
27
26
|
basic.pause(500)
|
|
28
27
|
```
|
|
29
28
|
|
|
30
|
-
## Step 3
|
|
29
|
+
## {Step 3}
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
Copy the code you've written and paste it at the end. In the copied code, change the ``||basic:Icon Names||`` to a **SMALL HEART**. Run your code in the on-screen micro:bit simulator. Do you see a big and small heart animation?
|
|
33
32
|
|
|
34
33
|
```spy
|
|
35
34
|
basic.showIcon(IconNames.Heart)
|
|
@@ -40,23 +39,9 @@ basic.clearScreen()
|
|
|
40
39
|
basic.pause(500)
|
|
41
40
|
```
|
|
42
41
|
|
|
43
|
-
## Step 4
|
|
42
|
+
## {Step 4}
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
```spy
|
|
48
|
-
basic.showIcon(IconNames.Heart)
|
|
49
|
-
basic.clearScreen()
|
|
50
|
-
basic.pause(500)
|
|
51
|
-
basic.showIcon(IconNames.SmallHeart)
|
|
52
|
-
basic.clearScreen()
|
|
53
|
-
basic.pause(500)
|
|
54
|
-
basic.showIcon(IconNames.Heart)
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## Step 5
|
|
58
|
-
|
|
59
|
-
Do you want your heart to flash continuously? Remove the last ``||basic:show icon||`` and then put a ``||basic:forever||`` loop around your code.
|
|
44
|
+
Now let's make our hearts flash forever! Put a ``||basic:forever||`` loop around your code.
|
|
60
45
|
|
|
61
46
|
```spy
|
|
62
47
|
basic.forever(function() {
|
|
@@ -69,6 +54,6 @@ basic.forever(function() {
|
|
|
69
54
|
})
|
|
70
55
|
```
|
|
71
56
|
|
|
72
|
-
## Step
|
|
57
|
+
## {Step 5}
|
|
73
58
|
|
|
74
|
-
If you have a @boardname@
|
|
59
|
+
If you have a @boardname@ device, connect it to your computer and click the ``|Download|`` button. Follow the instructions to transfer your code onto the @boardname@ and watch the hearts flash! ⭐ Great job! ⭐
|
|
@@ -2,48 +2,66 @@
|
|
|
2
2
|
|
|
3
3
|
### @explicitHints true
|
|
4
4
|
|
|
5
|
-
## Introduction @unplugged
|
|
5
|
+
## {Introduction @unplugged}
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
How much love 😍 are you emitting today? Create a 💓 LOVE METER 💓 machine with your micro:bit!
|
|
8
8
|
|
|
9
9
|

|
|
10
10
|
|
|
11
|
-
## Step 1
|
|
11
|
+
## {Step 1}
|
|
12
12
|
|
|
13
|
-
Add an
|
|
13
|
+
Add an input ``||input:on pin pressed||`` function to run code when Pin P0 is pressed on the micro:bit. Type the code below, or drag a code snippet from the ``||input:Input||`` Toolbox category.
|
|
14
14
|
|
|
15
15
|
```spy
|
|
16
16
|
input.onPinPressed(TouchPin.P0, function() {
|
|
17
17
|
})
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
## Step 2
|
|
20
|
+
## {Step 2}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
between `0` to `100` when pin **0** is pressed.
|
|
22
|
+
Write some code to show a number in the ``||input:on pin pressed||`` function, using the basic ``||basic:show number||`` function.
|
|
24
23
|
|
|
25
24
|
```spy
|
|
26
25
|
input.onPinPressed(TouchPin.P0, function() {
|
|
27
|
-
basic.showNumber(
|
|
28
|
-
})
|
|
26
|
+
basic.showNumber(0)
|
|
27
|
+
})
|
|
29
28
|
```
|
|
30
29
|
|
|
31
|
-
## Step 3
|
|
30
|
+
## {Step 3}
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
Instead of showing 0, use the ``||math:randint||`` function to show a random number between a minimum and maximum value.
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
```spy
|
|
35
|
+
input.onPinPressed(TouchPin.P0, function() {
|
|
36
|
+
basic.showNumber(randint(0, 10))
|
|
37
|
+
})
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## {Step 4}
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
Everyone knows that love can be measured on a scale of 0 to 100. So, in the ``||math:randint||`` function, change the maximum value to **100**.
|
|
43
|
+
|
|
44
|
+
```spy
|
|
45
|
+
input.onPinPressed(TouchPin.P0, function() {
|
|
46
|
+
basic.showNumber(randint(0, 100))
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## {Step 5}
|
|
51
|
+
|
|
52
|
+
Now let's be sure to label our Love Machine! Use the basic ``||basic:show string||`` function to show the message "LOVE METER" on the screen of the micro:bit.
|
|
38
53
|
|
|
39
54
|
```spy
|
|
40
55
|
basic.showString("LOVE METER")
|
|
41
56
|
input.onPinPressed(TouchPin.P0, function() {
|
|
42
57
|
basic.showNumber(randint(0, 100));
|
|
43
|
-
})
|
|
58
|
+
})
|
|
44
59
|
```
|
|
45
60
|
|
|
46
|
-
## Step
|
|
61
|
+
## {Step 6}
|
|
62
|
+
|
|
63
|
+
Let's test our code. Press **Pin 0** on the micro:bit on-screen simulator (bottom left). Numbers between 0-25 = 🖤 No Love, 26-50 = 🫶 BFF Love, 51-75 = 💘 Brokenhearted Love, 76-100 = 💖🔥 Fiery Hot Love!
|
|
64
|
+
|
|
65
|
+
## {Step 7}
|
|
47
66
|
|
|
48
|
-
|
|
49
|
-
and press pin **0** with the other hand to trigger this code.
|
|
67
|
+
If you have a @boardname@ device, connect it to your computer and click the ``|Download|`` button. Follow the instructions to transfer your code onto the @boardname@. Once your code has been downloaded, hold the **GND** pin with one hand and touch the **0** pin with the other hand. Your micro:bit 💓 LOVE METER 💓 machine will detect the love current flowing through your body!
|