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/docs/projects/karel.md
CHANGED
|
@@ -56,7 +56,7 @@ For patterns that you design, decide which LEDs you want to turn on and then mak
|
|
|
56
56
|
Figure out how to make the first letter of your name with the LEDs.
|
|
57
57
|
|
|
58
58
|
```sim
|
|
59
|
-
basic.forever(()
|
|
59
|
+
basic.forever(function () {
|
|
60
60
|
basic.showAnimation(`
|
|
61
61
|
# # # . . # # # . . # # # . . # # # . .
|
|
62
62
|
. . . . . # . . . . # . . . . # . . # .
|
|
@@ -75,7 +75,7 @@ basic.forever(() => {
|
|
|
75
75
|
Make something fun!
|
|
76
76
|
|
|
77
77
|
```sim
|
|
78
|
-
basic.forever(()
|
|
78
|
+
basic.forever(function () {
|
|
79
79
|
basic.showAnimation(`
|
|
80
80
|
# . . . . # . . . . # . . . . # . . . . # . . . . # . . . .
|
|
81
81
|
. . . . . # . . . . # . . . . # . . . . # . . . # # . # # #
|
|
@@ -99,86 +99,86 @@ Copy this code into the JavaScript editor and then download it to the board.
|
|
|
99
99
|
|
|
100
100
|
```typescript
|
|
101
101
|
class Board {
|
|
102
|
-
public isKarelActive: boolean
|
|
103
|
-
public karelX: number
|
|
104
|
-
public karelY: number
|
|
102
|
+
public isKarelActive: boolean
|
|
103
|
+
public karelX: number
|
|
104
|
+
public karelY: number
|
|
105
105
|
|
|
106
|
-
public ledState: Image
|
|
107
|
-
private karelDirection: Direction
|
|
106
|
+
public ledState: Image
|
|
107
|
+
private karelDirection: Direction
|
|
108
108
|
|
|
109
109
|
constructor() {
|
|
110
|
-
this.isKarelActive = true
|
|
111
|
-
this.karelX = 2
|
|
112
|
-
this.karelY = 2
|
|
113
|
-
this.karelDirection = Direction.UP
|
|
110
|
+
this.isKarelActive = true
|
|
111
|
+
this.karelX = 2
|
|
112
|
+
this.karelY = 2
|
|
113
|
+
this.karelDirection = Direction.UP
|
|
114
114
|
this.ledState = images.createImage(`
|
|
115
115
|
. . . . .
|
|
116
116
|
. . . . .
|
|
117
117
|
. . . . .
|
|
118
118
|
. . . . .
|
|
119
119
|
. . . . .
|
|
120
|
-
`)
|
|
120
|
+
`)
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
pressedA() {
|
|
124
124
|
if (!this.isKarelActive) {
|
|
125
|
-
return
|
|
125
|
+
return
|
|
126
126
|
}
|
|
127
|
-
this.karelDirection = (this.karelDirection + 1) % 4
|
|
127
|
+
this.karelDirection = (this.karelDirection + 1) % 4
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
pressedB() {
|
|
131
131
|
if (!this.isKarelActive) {
|
|
132
|
-
return
|
|
132
|
+
return
|
|
133
133
|
}
|
|
134
|
-
this.ledState.setPixel(this.karelX, this.karelY, true)
|
|
134
|
+
this.ledState.setPixel(this.karelX, this.karelY, true)
|
|
135
135
|
this.moveKarel()
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
shake() {
|
|
139
139
|
if (!this.isKarelActive) {
|
|
140
|
-
return
|
|
140
|
+
return
|
|
141
141
|
}
|
|
142
142
|
this.moveKarel()
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
private moveKarel() {
|
|
146
146
|
if (!this.isKarelActive) {
|
|
147
|
-
return
|
|
147
|
+
return
|
|
148
148
|
}
|
|
149
149
|
switch (this.karelDirection) {
|
|
150
150
|
case Direction.UP:
|
|
151
151
|
if (this.karelY > 0) {
|
|
152
|
-
this.karelY -= 1
|
|
152
|
+
this.karelY -= 1
|
|
153
153
|
}
|
|
154
|
-
break
|
|
154
|
+
break
|
|
155
155
|
case Direction.LEFT:
|
|
156
156
|
if (this.karelX > 0) {
|
|
157
|
-
this.karelX -= 1
|
|
157
|
+
this.karelX -= 1
|
|
158
158
|
}
|
|
159
|
-
break
|
|
159
|
+
break
|
|
160
160
|
case Direction.DOWN:
|
|
161
161
|
if (this.karelY < 4) {
|
|
162
|
-
this.karelY += 1
|
|
162
|
+
this.karelY += 1
|
|
163
163
|
}
|
|
164
|
-
break
|
|
164
|
+
break
|
|
165
165
|
case Direction.RIGHT:
|
|
166
166
|
if (this.karelX < 4) {
|
|
167
|
-
this.karelX += 1
|
|
167
|
+
this.karelX += 1
|
|
168
168
|
}
|
|
169
|
-
break
|
|
169
|
+
break
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
pressedAB() {
|
|
174
|
-
this.isKarelActive = !this.isKarelActive
|
|
174
|
+
this.isKarelActive = !this.isKarelActive
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
update() {
|
|
178
|
-
this.ledState.showImage(0)
|
|
178
|
+
this.ledState.showImage(0)
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
|
-
const board = new Board()
|
|
181
|
+
const board = new Board()
|
|
182
182
|
enum Direction {
|
|
183
183
|
UP = 0,
|
|
184
184
|
LEFT,
|
|
@@ -186,21 +186,21 @@ enum Direction {
|
|
|
186
186
|
RIGHT
|
|
187
187
|
}
|
|
188
188
|
input.onButtonPressed(Button.B, function () {
|
|
189
|
-
board.pressedB()
|
|
190
|
-
board.update()
|
|
189
|
+
board.pressedB()
|
|
190
|
+
board.update()
|
|
191
191
|
})
|
|
192
192
|
input.onGesture(Gesture.Shake, function () {
|
|
193
|
-
board.shake()
|
|
194
|
-
board.update()
|
|
193
|
+
board.shake()
|
|
194
|
+
board.update()
|
|
195
195
|
})
|
|
196
196
|
|
|
197
197
|
input.onButtonPressed(Button.A, function () {
|
|
198
|
-
board.pressedA()
|
|
199
|
-
board.update()
|
|
198
|
+
board.pressedA()
|
|
199
|
+
board.update()
|
|
200
200
|
})
|
|
201
201
|
input.onButtonPressed(Button.AB, function () {
|
|
202
|
-
board.pressedAB()
|
|
203
|
-
board.update()
|
|
202
|
+
board.pressedAB()
|
|
203
|
+
board.update()
|
|
204
204
|
})
|
|
205
205
|
basic.forever(function () {
|
|
206
206
|
if (board.isKarelActive) {
|
|
@@ -13,7 +13,7 @@ Add code to open the mouth when light is detected.
|
|
|
13
13
|
We are going to add code to open the mouth proportionally to the amount of light on the @boardname@. The code is in a loop so we'll continually read the light level and map it to an angle using the ``||pins:map||`` function.
|
|
14
14
|
|
|
15
15
|
```blocks
|
|
16
|
-
basic.forever(()
|
|
16
|
+
basic.forever(function () {
|
|
17
17
|
pins.servoWritePin(AnalogPin.P0, pins.map(
|
|
18
18
|
input.lightLevel(),
|
|
19
19
|
0,
|
|
@@ -11,13 +11,13 @@ Remote control your monster with another @boardname@.
|
|
|
11
11
|
You will need one more @boardname@ for this part. By using the radio, we can control the monster with another @boardname@. Download the code below to the @boardname@ on the monster and then again onto a "controller" @boardname@. Whenever button **A** is pressed, the monster's mouth moves once.
|
|
12
12
|
|
|
13
13
|
```blocks
|
|
14
|
-
radio.onReceivedNumber((
|
|
14
|
+
radio.onReceivedNumber(function(receivedNumber) {
|
|
15
15
|
pins.servoWritePin(AnalogPin.P0, 30)
|
|
16
16
|
basic.pause(500)
|
|
17
17
|
pins.servoWritePin(AnalogPin.P0, 150)
|
|
18
18
|
basic.pause(500)
|
|
19
19
|
})
|
|
20
|
-
input.onButtonPressed(Button.A, ()
|
|
20
|
+
input.onButtonPressed(Button.A, function () {
|
|
21
21
|
radio.sendNumber(0)
|
|
22
22
|
})
|
|
23
23
|
```
|
|
@@ -23,10 +23,10 @@ The only things you need for this trick are your @boardname@ and any magnet that
|
|
|
23
23
|
Before we code the trick itself, we need to get the buttons working as you would expect them to such that pressing button **A** displays 'A' and pressing button **B** displays 'B':
|
|
24
24
|
|
|
25
25
|
```blocks
|
|
26
|
-
input.onButtonPressed(Button.A, ()
|
|
26
|
+
input.onButtonPressed(Button.A, function () {
|
|
27
27
|
basic.showString("A")
|
|
28
28
|
})
|
|
29
|
-
input.onButtonPressed(Button.B, ()
|
|
29
|
+
input.onButtonPressed(Button.B, function () {
|
|
30
30
|
basic.showString("B")
|
|
31
31
|
})
|
|
32
32
|
```
|
|
@@ -48,7 +48,7 @@ If you've ever played with magnets you know they have two ends, often called a N
|
|
|
48
48
|
So, in the code below, we will check if the absolute value of our magnetic field strength reading is more than `100` and save the result of that check in a new variable called ``isSwitched``:
|
|
49
49
|
|
|
50
50
|
```blocks
|
|
51
|
-
let force = Math.abs(input.magneticForce(Dimension.Strength))
|
|
51
|
+
let force = Math.abs(input.magneticForce(Dimension.Strength))
|
|
52
52
|
let isSwitched = force > 100
|
|
53
53
|
```
|
|
54
54
|
## Step 4: Running our 'magnet nearby' check all the time
|
|
@@ -56,10 +56,10 @@ let isSwitched = force > 100
|
|
|
56
56
|
At the moment, our code to detect a magnet being nearby will only run once. We need to put it into a ``||basic:forever||`` loop so that it keeps running again and again, checking for the magnet to come near to the @boardname@. We should also make sure ``isSwitched`` is set to `false` when our program starts.
|
|
57
57
|
|
|
58
58
|
```blocks
|
|
59
|
-
let force = 0
|
|
60
|
-
let isSwitched = false
|
|
61
|
-
basic.forever(()
|
|
62
|
-
force = Math.abs(input.magneticForce(Dimension.Strength))
|
|
59
|
+
let force = 0
|
|
60
|
+
let isSwitched = false
|
|
61
|
+
basic.forever(function () {
|
|
62
|
+
force = Math.abs(input.magneticForce(Dimension.Strength))
|
|
63
63
|
isSwitched = force > 100
|
|
64
64
|
})
|
|
65
65
|
```
|
|
@@ -69,21 +69,21 @@ basic.forever(() => {
|
|
|
69
69
|
Now we can check the value of our variable ``isSwitched`` whenever we want and we will know that the magnet is nearby if it's value is `true`. Let's use that to change how the buttons work and complete the code for our trick. We will add an ``||logic:if then else||`` block to each button's code and check if we should swap over what's displayed for each button if ``isSwitched`` is equal to `true`:
|
|
70
70
|
|
|
71
71
|
```blocks
|
|
72
|
-
let force = 0
|
|
73
|
-
let isSwitched = false
|
|
74
|
-
basic.forever(()
|
|
75
|
-
force = Math.abs(input.magneticForce(Dimension.Strength))
|
|
72
|
+
let force = 0
|
|
73
|
+
let isSwitched = false
|
|
74
|
+
basic.forever(function () {
|
|
75
|
+
force = Math.abs(input.magneticForce(Dimension.Strength))
|
|
76
76
|
isSwitched = force > 100
|
|
77
77
|
})
|
|
78
78
|
|
|
79
|
-
input.onButtonPressed(Button.A, ()
|
|
79
|
+
input.onButtonPressed(Button.A, function () {
|
|
80
80
|
if (isSwitched) {
|
|
81
81
|
basic.showString("B")
|
|
82
82
|
} else {
|
|
83
83
|
basic.showString("A")
|
|
84
84
|
}
|
|
85
85
|
})
|
|
86
|
-
input.onButtonPressed(Button.B, ()
|
|
86
|
+
input.onButtonPressed(Button.B, function () {
|
|
87
87
|
if (isSwitched) {
|
|
88
88
|
basic.showString("A")
|
|
89
89
|
} else {
|
|
@@ -43,7 +43,7 @@ The code uses blocks from the [radio-blockchain](https://makecode.microbit.org/p
|
|
|
43
43
|
|
|
44
44
|
```blocks
|
|
45
45
|
// shaking is mining...
|
|
46
|
-
input.onGesture(Gesture.Shake, ()
|
|
46
|
+
input.onGesture(Gesture.Shake, function () {
|
|
47
47
|
led.stopAnimation()
|
|
48
48
|
basic.clearScreen()
|
|
49
49
|
basic.pause(200) // display a short pause
|
|
@@ -58,7 +58,7 @@ input.onGesture(Gesture.Shake, () => {
|
|
|
58
58
|
})
|
|
59
59
|
|
|
60
60
|
// show my coins
|
|
61
|
-
input.onButtonPressed(Button.A, ()
|
|
61
|
+
input.onButtonPressed(Button.A, function () {
|
|
62
62
|
led.stopAnimation()
|
|
63
63
|
let coins = blockchain.valuesFrom(blockchain.id()).length;
|
|
64
64
|
basic.showNumber(coins);
|
|
@@ -66,7 +66,7 @@ input.onButtonPressed(Button.A, () => {
|
|
|
66
66
|
})
|
|
67
67
|
|
|
68
68
|
// show the block chain size
|
|
69
|
-
input.onButtonPressed(Button.B, ()
|
|
69
|
+
input.onButtonPressed(Button.B, function () {
|
|
70
70
|
led.stopAnimation()
|
|
71
71
|
basic.showNumber(blockchain.length());
|
|
72
72
|
basic.showString("BLOCKS");
|
|
@@ -18,10 +18,10 @@ https://youtu.be/m-HS8OyS0pw
|
|
|
18
18
|
|
|
19
19
|
## Step 2: code light sensor
|
|
20
20
|
|
|
21
|
-
Code the
|
|
21
|
+
Code the light sensor on the @boardname@ to control the servo.
|
|
22
22
|
|
|
23
23
|
```blocks
|
|
24
|
-
basic.forever(()
|
|
24
|
+
basic.forever(function () {
|
|
25
25
|
led.plotBarGraph(
|
|
26
26
|
input.lightLevel(),
|
|
27
27
|
0
|
|
@@ -48,7 +48,7 @@ angle range, ``[closed, opened]`` using ``pins.map``.
|
|
|
48
48
|
let angle = 0
|
|
49
49
|
let closed = 0
|
|
50
50
|
let opened = 0
|
|
51
|
-
basic.forever(()
|
|
51
|
+
basic.forever(function () {
|
|
52
52
|
led.plotBarGraph(
|
|
53
53
|
input.lightLevel(),
|
|
54
54
|
0
|
|
@@ -12,13 +12,13 @@ You will need 2 @boardname@ for this part. By using the radio, we can make the M
|
|
|
12
12
|
Download the code below to the @boardname@ on the Milk Carton Monster and another "controller" @boardname@. Whenever ``A`` is pressed, the Milk Carton Monster will move once.
|
|
13
13
|
|
|
14
14
|
```blocks
|
|
15
|
-
radio.onReceivedNumber((receivedNumber)
|
|
15
|
+
radio.onReceivedNumber(function(receivedNumber) {
|
|
16
16
|
pins.servoWritePin(AnalogPin.P0, 0)
|
|
17
17
|
basic.pause(500)
|
|
18
18
|
pins.servoWritePin(AnalogPin.P0, 180)
|
|
19
19
|
basic.pause(500)
|
|
20
20
|
})
|
|
21
|
-
input.onButtonPressed(Button.A, ()
|
|
21
|
+
input.onButtonPressed(Button.A, function () {
|
|
22
22
|
radio.sendNumber(0)
|
|
23
23
|
})
|
|
24
24
|
```
|
|
@@ -17,11 +17,11 @@ In order for the Milky Monster to move, the @boardname@ needs to command the ser
|
|
|
17
17
|
- Press button ``B`` to switch the servo to 0 degrees (to open the mouth of Milky Monster).
|
|
18
18
|
|
|
19
19
|
```blocks
|
|
20
|
-
input.onButtonPressed(Button.A, ()
|
|
20
|
+
input.onButtonPressed(Button.A, function () {
|
|
21
21
|
pins.servoWritePin(AnalogPin.P0, 180)
|
|
22
22
|
basic.showNumber(180)
|
|
23
23
|
})
|
|
24
|
-
input.onButtonPressed(Button.B, ()
|
|
24
|
+
input.onButtonPressed(Button.B, function () {
|
|
25
25
|
pins.servoWritePin(AnalogPin.P0, 0)
|
|
26
26
|
basic.showNumber(0)
|
|
27
27
|
})
|
|
@@ -64,7 +64,7 @@ https://youtu.be/fAR58GJUZdM
|
|
|
64
64
|
Code the light sensor on the @boardname@ to control the servo.
|
|
65
65
|
|
|
66
66
|
```blocks
|
|
67
|
-
basic.forever(()
|
|
67
|
+
basic.forever(function () {
|
|
68
68
|
pins.servoWritePin(AnalogPin.P0, input.lightLevel())
|
|
69
69
|
led.plotBarGraph(
|
|
70
70
|
input.lightLevel(),
|
|
@@ -12,13 +12,13 @@ You will need a second @boardname@ for this part. By using the radio, we can con
|
|
|
12
12
|
Download the code below to the @boardname@ that's on the Milky Monster and again to another "controller" @boardname@. Whenever button **A** is pressed, the Milky Monster will move one time.
|
|
13
13
|
|
|
14
14
|
```blocks
|
|
15
|
-
radio.onReceivedNumber((receivedNumber)
|
|
15
|
+
radio.onReceivedNumber(function(receivedNumber) {
|
|
16
16
|
pins.servoWritePin(AnalogPin.P0, 0)
|
|
17
17
|
basic.pause(500)
|
|
18
18
|
pins.servoWritePin(AnalogPin.P0, 180)
|
|
19
19
|
basic.pause(500)
|
|
20
20
|
})
|
|
21
|
-
input.onButtonPressed(Button.A, ()
|
|
21
|
+
input.onButtonPressed(Button.A, function () {
|
|
22
22
|
radio.sendNumber(0)
|
|
23
23
|
})
|
|
24
24
|
```
|
|
@@ -16,7 +16,7 @@ Let's add blocks that send a number when button ``A`` is pressed. We assume that
|
|
|
16
16
|
|
|
17
17
|
```blocks
|
|
18
18
|
radio.setGroup(1)
|
|
19
|
-
input.onButtonPressed(Button.A, ()
|
|
19
|
+
input.onButtonPressed(Button.A, function () {
|
|
20
20
|
radio.sendNumber(0)
|
|
21
21
|
basic.showIcon(IconNames.Happy)
|
|
22
22
|
})
|
|
@@ -41,7 +41,7 @@ radio.onReceivedNumber(function (receivedNumber) {
|
|
|
41
41
|
Adding another mood to our messaging app done in a similar way. We decide that the "mood code" of `1` means **frowny**. We can add a ``B`` button event that sends that code.
|
|
42
42
|
|
|
43
43
|
```blocks
|
|
44
|
-
input.onButtonPressed(Button.B, ()
|
|
44
|
+
input.onButtonPressed(Button.B, function () {
|
|
45
45
|
radio.sendNumber(1)
|
|
46
46
|
basic.showIcon(IconNames.Sad)
|
|
47
47
|
})
|
|
@@ -70,11 +70,11 @@ Try adding a new code and use the ``||input:on shake||`` event to send it.
|
|
|
70
70
|
|
|
71
71
|
```blocks
|
|
72
72
|
radio.setGroup(1)
|
|
73
|
-
input.onButtonPressed(Button.A, ()
|
|
73
|
+
input.onButtonPressed(Button.A, function () {
|
|
74
74
|
radio.sendNumber(0)
|
|
75
75
|
basic.showIcon(IconNames.Happy)
|
|
76
76
|
})
|
|
77
|
-
input.onButtonPressed(Button.B, ()
|
|
77
|
+
input.onButtonPressed(Button.B, function () {
|
|
78
78
|
radio.sendNumber(1)
|
|
79
79
|
basic.showIcon(IconNames.Sad)
|
|
80
80
|
})
|
|
@@ -30,7 +30,7 @@ radio.setTransmitSerialNumber(true)
|
|
|
30
30
|
radio.setGroup(4)
|
|
31
31
|
led.setBrightness(64)
|
|
32
32
|
let reading = 0
|
|
33
|
-
basic.forever(()
|
|
33
|
+
basic.forever(function () {
|
|
34
34
|
pins.analogWritePin(AnalogPin.P1, 1023)
|
|
35
35
|
reading = pins.analogReadPin(AnalogPin.P0)
|
|
36
36
|
radio.sendNumber(reading / 4);
|
|
@@ -15,7 +15,7 @@ We are going to use the light sensor to detect if a train is passing. We will do
|
|
|
15
15
|
Let's first explore how the light sensor works by downloading the following program onto our @boardname@.
|
|
16
16
|
|
|
17
17
|
```block
|
|
18
|
-
input.onButtonPressed(Button.A, ()
|
|
18
|
+
input.onButtonPressed(Button.A, function () {
|
|
19
19
|
basic.showNumber(input.lightLevel())
|
|
20
20
|
})
|
|
21
21
|
```
|
|
@@ -49,7 +49,7 @@ Add the following blocks to your program to make the top-left led indicate if a
|
|
|
49
49
|
Replace 40 with your threshold.
|
|
50
50
|
|
|
51
51
|
```block
|
|
52
|
-
basic.forever(()
|
|
52
|
+
basic.forever(function () {
|
|
53
53
|
if (input.lightLevel() < 40) {
|
|
54
54
|
led.plot(0, 0)
|
|
55
55
|
} else {
|
|
@@ -95,7 +95,7 @@ We can turn on one LED by writing a digital 1 to one pin and a digital 0 to the
|
|
|
95
95
|
Now use the following program to make the lights blink indefinitely.
|
|
96
96
|
|
|
97
97
|
```block
|
|
98
|
-
basic.forever(()
|
|
98
|
+
basic.forever(function () {
|
|
99
99
|
pins.digitalWritePin(DigitalPin.P1, 1)
|
|
100
100
|
pins.digitalWritePin(DigitalPin.P2, 0)
|
|
101
101
|
basic.pause(300)
|
|
@@ -120,11 +120,11 @@ First of all, remove the forever block from step 5. Then add the following code:
|
|
|
120
120
|
```block
|
|
121
121
|
let flashes_remaining = 0
|
|
122
122
|
|
|
123
|
-
input.onButtonPressed(Button.B, ()
|
|
123
|
+
input.onButtonPressed(Button.B, function () {
|
|
124
124
|
flashes_remaining = 5
|
|
125
125
|
})
|
|
126
126
|
|
|
127
|
-
basic.forever(()
|
|
127
|
+
basic.forever(function () {
|
|
128
128
|
while (flashes_remaining > 0) {
|
|
129
129
|
pins.digitalWritePin(DigitalPin.P1, 0)
|
|
130
130
|
pins.digitalWritePin(DigitalPin.P2, 1)
|
|
@@ -18,7 +18,7 @@ https://youtu.be/pD6tM1nXCPA
|
|
|
18
18
|
The first program has the car drive around in a circle for 5 seconds when the user presses the ``A`` button. This is simply done by turning both motor controllers on for 5 seconds.
|
|
19
19
|
|
|
20
20
|
```blocks-ignore
|
|
21
|
-
input.onButtonPressed(Button.A, ()
|
|
21
|
+
input.onButtonPressed(Button.A, function () {
|
|
22
22
|
basic.showIcon(IconNames.Happy)
|
|
23
23
|
kitronik.motorOn(kitronik.Motors.Motor1, kitronik.MotorDirection.Reverse, 100)
|
|
24
24
|
kitronik.motorOn(kitronik.Motors.Motor2, kitronik.MotorDirection.Forward, 100)
|
|
@@ -46,7 +46,7 @@ https://youtu.be/agor9wtiAkE
|
|
|
46
46
|
Instead of stopping after 5 seconds, we reverse the steering motor to turn in the other direction. This will create a figure eight path.
|
|
47
47
|
|
|
48
48
|
```blocks-ignore
|
|
49
|
-
input.onButtonPressed(Button.A, ()
|
|
49
|
+
input.onButtonPressed(Button.A, function () {
|
|
50
50
|
basic.showIcon(IconNames.Happy)
|
|
51
51
|
kitronik.motorOn(kitronik.Motors.Motor1, kitronik.MotorDirection.Reverse, 100)
|
|
52
52
|
kitronik.motorOn(kitronik.Motors.Motor2, kitronik.MotorDirection.Forward, 100)
|
|
@@ -14,23 +14,23 @@ radio.onReceivedValue(function (name: string, value: number) {
|
|
|
14
14
|
led.toggle(0, 0)
|
|
15
15
|
if (name == "throttle") {
|
|
16
16
|
if (value > 0) {
|
|
17
|
-
kitronik.motorOn(kitronik.Motors.Motor1, kitronik.MotorDirection.Reverse, 100)
|
|
17
|
+
kitronik.motorOn(kitronik.Motors.Motor1, kitronik.MotorDirection.Reverse, 100)
|
|
18
18
|
} else if (value < 0) {
|
|
19
|
-
kitronik.motorOn(kitronik.Motors.Motor1, kitronik.MotorDirection.Forward, 100)
|
|
19
|
+
kitronik.motorOn(kitronik.Motors.Motor1, kitronik.MotorDirection.Forward, 100)
|
|
20
20
|
} else {
|
|
21
21
|
kitronik.motorOff(kitronik.Motors.Motor1);
|
|
22
22
|
}
|
|
23
23
|
} else if (name == "steering") {
|
|
24
24
|
if (value > 0) {
|
|
25
|
-
kitronik.motorOn(kitronik.Motors.Motor2, kitronik.MotorDirection.Forward, 100)
|
|
25
|
+
kitronik.motorOn(kitronik.Motors.Motor2, kitronik.MotorDirection.Forward, 100)
|
|
26
26
|
} else if (value < 0) {
|
|
27
|
-
kitronik.motorOn(kitronik.Motors.Motor2, kitronik.MotorDirection.Reverse, 100)
|
|
27
|
+
kitronik.motorOn(kitronik.Motors.Motor2, kitronik.MotorDirection.Reverse, 100)
|
|
28
28
|
} else {
|
|
29
|
-
kitronik.motorOff(kitronik.Motors.Motor2)
|
|
29
|
+
kitronik.motorOff(kitronik.Motors.Motor2)
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
})
|
|
33
|
-
basic.forever(()
|
|
33
|
+
basic.forever(function () {
|
|
34
34
|
throttle = 0
|
|
35
35
|
if (input.buttonIsPressed(Button.A)) {
|
|
36
36
|
throttle = 100
|
|
@@ -46,10 +46,10 @@ let start = 0
|
|
|
46
46
|
let end = 0
|
|
47
47
|
let false_start = false
|
|
48
48
|
let running = false
|
|
49
|
-
input.onPinPressed(TouchPin.P0, ()
|
|
49
|
+
input.onPinPressed(TouchPin.P0, function () {
|
|
50
50
|
|
|
51
51
|
})
|
|
52
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
52
|
+
input.onPinPressed(TouchPin.P1, function () {
|
|
53
53
|
|
|
54
54
|
})
|
|
55
55
|
running = false
|
|
@@ -67,13 +67,13 @@ let start = 0
|
|
|
67
67
|
let end = 0
|
|
68
68
|
let false_start = false
|
|
69
69
|
let running = false
|
|
70
|
-
input.onPinPressed(TouchPin.P0, ()
|
|
70
|
+
input.onPinPressed(TouchPin.P0, function () {
|
|
71
71
|
basic.showNumber(3)
|
|
72
72
|
basic.showNumber(2)
|
|
73
73
|
basic.showNumber(1)
|
|
74
74
|
basic.clearScreen()
|
|
75
75
|
})
|
|
76
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
76
|
+
input.onPinPressed(TouchPin.P1, function () {
|
|
77
77
|
|
|
78
78
|
})
|
|
79
79
|
running = false
|
|
@@ -93,7 +93,7 @@ let start = 0
|
|
|
93
93
|
let end = 0
|
|
94
94
|
let false_start = false
|
|
95
95
|
let running = false
|
|
96
|
-
input.onPinPressed(TouchPin.P0, ()
|
|
96
|
+
input.onPinPressed(TouchPin.P0, function () {
|
|
97
97
|
basic.showNumber(3)
|
|
98
98
|
basic.showNumber(2)
|
|
99
99
|
basic.showNumber(1)
|
|
@@ -101,7 +101,7 @@ input.onPinPressed(TouchPin.P0, () => {
|
|
|
101
101
|
running = false
|
|
102
102
|
false_start = false
|
|
103
103
|
})
|
|
104
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
104
|
+
input.onPinPressed(TouchPin.P1, function () {
|
|
105
105
|
|
|
106
106
|
})
|
|
107
107
|
running = false
|
|
@@ -119,7 +119,7 @@ let start = 0
|
|
|
119
119
|
let end = 0
|
|
120
120
|
let false_start = false
|
|
121
121
|
let running = false
|
|
122
|
-
input.onPinPressed(TouchPin.P0, ()
|
|
122
|
+
input.onPinPressed(TouchPin.P0, function () {
|
|
123
123
|
basic.showNumber(3)
|
|
124
124
|
basic.showNumber(2)
|
|
125
125
|
basic.showNumber(1)
|
|
@@ -128,7 +128,7 @@ input.onPinPressed(TouchPin.P0, () => {
|
|
|
128
128
|
false_start = false
|
|
129
129
|
basic.pause(1000 + randint(0, 2000))
|
|
130
130
|
})
|
|
131
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
131
|
+
input.onPinPressed(TouchPin.P1, function () {
|
|
132
132
|
|
|
133
133
|
})
|
|
134
134
|
running = false
|
|
@@ -146,10 +146,10 @@ let start = 0
|
|
|
146
146
|
let end = 0
|
|
147
147
|
let false_start = false
|
|
148
148
|
let running = false
|
|
149
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
149
|
+
input.onPinPressed(TouchPin.P1, function () {
|
|
150
150
|
|
|
151
151
|
})
|
|
152
|
-
input.onPinPressed(TouchPin.P0, ()
|
|
152
|
+
input.onPinPressed(TouchPin.P0, function () {
|
|
153
153
|
basic.showNumber(3)
|
|
154
154
|
basic.showNumber(2)
|
|
155
155
|
basic.showNumber(1)
|
|
@@ -184,7 +184,7 @@ let start = 0
|
|
|
184
184
|
let end = 0
|
|
185
185
|
let false_start = false
|
|
186
186
|
let running = false
|
|
187
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
187
|
+
input.onPinPressed(TouchPin.P1, function () {
|
|
188
188
|
if (running) {
|
|
189
189
|
running = false
|
|
190
190
|
end = input.runningTime()
|
|
@@ -208,7 +208,7 @@ input.onPinPressed(TouchPin.P1, () => {
|
|
|
208
208
|
`)
|
|
209
209
|
}
|
|
210
210
|
})
|
|
211
|
-
input.onPinPressed(TouchPin.P0, ()
|
|
211
|
+
input.onPinPressed(TouchPin.P0, function () {
|
|
212
212
|
basic.showNumber(3)
|
|
213
213
|
basic.showNumber(2)
|
|
214
214
|
basic.showNumber(1)
|
|
@@ -241,7 +241,7 @@ let start = 0
|
|
|
241
241
|
let end = 0
|
|
242
242
|
let false_start = false
|
|
243
243
|
let running = false
|
|
244
|
-
input.onPinPressed(TouchPin.P0, ()
|
|
244
|
+
input.onPinPressed(TouchPin.P0, function () {
|
|
245
245
|
basic.showNumber(3)
|
|
246
246
|
basic.showNumber(2)
|
|
247
247
|
basic.showNumber(1)
|
|
@@ -257,7 +257,7 @@ input.onPinPressed(TouchPin.P0, () => {
|
|
|
257
257
|
led.plot(randint(0, 4), randint(0, 4))
|
|
258
258
|
}
|
|
259
259
|
})
|
|
260
|
-
input.onPinPressed(TouchPin.P1, ()
|
|
260
|
+
input.onPinPressed(TouchPin.P1, function () {
|
|
261
261
|
if (running) {
|
|
262
262
|
running = false
|
|
263
263
|
end = input.runningTime()
|
|
@@ -281,7 +281,7 @@ input.onPinPressed(TouchPin.P1, () => {
|
|
|
281
281
|
`)
|
|
282
282
|
}
|
|
283
283
|
})
|
|
284
|
-
input.onPinPressed(TouchPin.P2, ()
|
|
284
|
+
input.onPinPressed(TouchPin.P2, function () {
|
|
285
285
|
if (running) {
|
|
286
286
|
running = false
|
|
287
287
|
end = input.runningTime()
|
package/docs/projects/salute.md
CHANGED
|
@@ -37,7 +37,7 @@ Choose a random number between 0 and 9.
|
|
|
37
37
|
|
|
38
38
|
```blocks
|
|
39
39
|
let randomNbr = 0
|
|
40
|
-
input.onGesture(Gesture.ScreenUp, ()
|
|
40
|
+
input.onGesture(Gesture.ScreenUp, function () {
|
|
41
41
|
randomNbr = randint(0, 10)
|
|
42
42
|
basic.showNumber(randomNbr)
|
|
43
43
|
})
|
|
@@ -47,7 +47,7 @@ Choose a random number between 1 and 9.
|
|
|
47
47
|
|
|
48
48
|
```blocks
|
|
49
49
|
let randomNbr = 0
|
|
50
|
-
input.onGesture(Gesture.ScreenUp, ()
|
|
50
|
+
input.onGesture(Gesture.ScreenUp, function () {
|
|
51
51
|
randomNbr = 0
|
|
52
52
|
while (randomNbr < 1) {
|
|
53
53
|
randomNbr = randint(0, 10)
|
|
@@ -63,13 +63,13 @@ The score keeper program adds one point for a player when button ``A`` or ``B``
|
|
|
63
63
|
```blocks
|
|
64
64
|
let player1Score = 0
|
|
65
65
|
let player2Score = 0
|
|
66
|
-
input.onButtonPressed(Button.A, ()
|
|
66
|
+
input.onButtonPressed(Button.A, function () {
|
|
67
67
|
player1Score += 1
|
|
68
68
|
})
|
|
69
|
-
input.onButtonPressed(Button.B, ()
|
|
69
|
+
input.onButtonPressed(Button.B, function () {
|
|
70
70
|
player2Score += 1
|
|
71
71
|
})
|
|
72
|
-
input.onButtonPressed(Button.AB, ()
|
|
72
|
+
input.onButtonPressed(Button.AB, function () {
|
|
73
73
|
if (player1Score == player2Score) {
|
|
74
74
|
basic.showString("TIE")
|
|
75
75
|
} else if (player1Score > player2Score) {
|
|
@@ -9,17 +9,17 @@ in a loop.
|
|
|
9
9
|
|
|
10
10
|
```blocks
|
|
11
11
|
let angle = 90
|
|
12
|
-
input.onButtonPressed(Button.A, ()
|
|
12
|
+
input.onButtonPressed(Button.A, function () {
|
|
13
13
|
angle = Math.max(0, angle - 5)
|
|
14
14
|
pins.servoWritePin(AnalogPin.P0, angle)
|
|
15
15
|
led.stopAnimation()
|
|
16
16
|
})
|
|
17
|
-
input.onButtonPressed(Button.B, ()
|
|
17
|
+
input.onButtonPressed(Button.B, function () {
|
|
18
18
|
angle = Math.min(180, angle + 5)
|
|
19
19
|
pins.servoWritePin(AnalogPin.P0, angle)
|
|
20
20
|
led.stopAnimation()
|
|
21
21
|
})
|
|
22
|
-
basic.forever(()
|
|
22
|
+
basic.forever(function () {
|
|
23
23
|
basic.showNumber(angle)
|
|
24
24
|
})
|
|
25
25
|
pins.servoWritePin(AnalogPin.P0, angle)
|