pxt-common-packages 13.2.2 → 13.2.4
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/common-sim.js +18 -6
- package/libs/base/docs/reference/control/device-long-serial-number.md +26 -0
- package/libs/base/docs/reference/control/device-serial-number.md +1 -0
- package/libs/base/docs/reference/math/constrain.md +36 -0
- package/libs/base/docs/reference/math/map.md +36 -0
- package/libs/color-coded-tilemap/docs/reference/color-coded-tilemap/tile-hit-from.md +81 -0
- package/libs/color-coded-tilemap/tilemap.ts +2 -2
- package/libs/controller/built/debug/binary.js +3 -3
- package/libs/controller---none/built/debug/binary.js +3 -3
- package/libs/core/docs/reference/control/device-dal-version.md +25 -0
- package/libs/core/docs/reference/control/millis.md +25 -0
- package/libs/core/docs/reference/control/pause-until.md +31 -0
- package/libs/core/docs/reference/control/raise-event.md +61 -0
- package/libs/core/docs/reference/control/reset.md +20 -0
- package/libs/core/docs/reference/control/seconds.md +24 -0
- package/libs/core/docs/reference/control.md +17 -0
- package/libs/core/timer.ts +4 -0
- package/libs/core---esp32/dal.d.ts +2 -0
- package/libs/core---esp32s2/dal.d.ts +2 -0
- package/libs/game/built/debug/binary.js +3 -3
- package/libs/game/docs/reference/game/runtime.md +46 -0
- package/libs/light/defaultlights.ts +1 -0
- package/libs/light/defaultlightsoverrides.ts +3 -0
- package/libs/light/docs/reference/light/create-apa102-strip.md +42 -0
- package/libs/light/docs/reference/light/default-strip.md +32 -0
- package/libs/light/docs/reference/light/neopixelstrip/set-gradient.md +31 -0
- package/libs/light/docs/reference/light/neopixelstrip/set-length.md +30 -0
- package/libs/light/docs/reference/light/neopixelstrip/set-mode.md +9 -0
- package/libs/light/docs/reference/light/onboard-strip.md +32 -0
- package/libs/light/docs/reference/light/range.md +61 -0
- package/libs/light/docs/reference/light/set-length.md +29 -0
- package/libs/light/docs/reference/light/set-mode.md +28 -0
- package/libs/light/neopixel.ts +2 -0
- package/libs/mixer/sim/music.ts +18 -6
- package/libs/mouse/docs/reference/mouse/click.md +38 -0
- package/libs/multiplayer/docs/reference/multiplayer/all-players.md +34 -0
- package/libs/multiplayer/docs/reference/multiplayer/is-connected.md +36 -0
- package/libs/multiplayer/player.ts +1 -1
- package/libs/music/docs/reference/music/play-tone.md +8 -3
- package/libs/music/docs/reference/music/set-tone.md +8 -3
- package/libs/net-game/built/debug/binary.js +3 -3
- package/libs/palette/built/debug/binary.js +3 -3
- package/libs/power/power.ts +4 -4
- package/libs/radio/docs/reference/radio/received-packet.md +39 -0
- package/libs/sprite-scaling/built/debug/binary.js +3 -3
- package/libs/storyboard/built/debug/binary.js +3 -3
- package/libs/switch/docs/reference/input/switch-right.md +27 -0
- package/libs/switch/shims.d.ts +2 -1
- package/libs/switch/switch.cpp +1 -0
- package/libs/touch/docs/reference/input/touch/threshold.md +33 -0
- package/package.json +1 -1
package/built/common-sim.js
CHANGED
|
@@ -3619,10 +3619,12 @@ var pxsim;
|
|
|
3619
3619
|
var music;
|
|
3620
3620
|
(function (music) {
|
|
3621
3621
|
function playInstructions(b) {
|
|
3622
|
+
setupOnStopAll();
|
|
3622
3623
|
return pxsim.AudioContextManager.playInstructionsAsync(b.data);
|
|
3623
3624
|
}
|
|
3624
3625
|
music.playInstructions = playInstructions;
|
|
3625
3626
|
function queuePlayInstructions(when, b) {
|
|
3627
|
+
setupOnStopAll();
|
|
3626
3628
|
pxsim.AudioContextManager.queuePlayInstructions(when, b);
|
|
3627
3629
|
}
|
|
3628
3630
|
music.queuePlayInstructions = queuePlayInstructions;
|
|
@@ -3644,15 +3646,25 @@ var pxsim;
|
|
|
3644
3646
|
music.SEQUENCER_LOOPED_MESSAGE = 3246;
|
|
3645
3647
|
let sequencers;
|
|
3646
3648
|
let nextSequencerId = 0;
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
+
let onStopAllSetup = false;
|
|
3650
|
+
function setupOnStopAll() {
|
|
3651
|
+
if (!onStopAllSetup) {
|
|
3652
|
+
onStopAllSetup = true;
|
|
3649
3653
|
pxsim.AudioContextManager.onStopAll(() => {
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
seq
|
|
3654
|
+
pxsim.AudioContextManager.muteAllChannels();
|
|
3655
|
+
if (sequencers) {
|
|
3656
|
+
for (const seq of sequencers) {
|
|
3657
|
+
seq.sequencer.stop();
|
|
3658
|
+
seq.sequencer.dispose();
|
|
3659
|
+
}
|
|
3660
|
+
sequencers = [];
|
|
3653
3661
|
}
|
|
3654
|
-
sequencers = [];
|
|
3655
3662
|
});
|
|
3663
|
+
}
|
|
3664
|
+
}
|
|
3665
|
+
async function _createSequencer() {
|
|
3666
|
+
setupOnStopAll();
|
|
3667
|
+
if (!sequencers) {
|
|
3656
3668
|
sequencers = [];
|
|
3657
3669
|
}
|
|
3658
3670
|
const res = {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# device Long Serial Number
|
|
2
|
+
|
|
3
|
+
Get the long (64-bit) serial number for the @boardname@
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
control.deviceSerialNumber()
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The system software in your board creates a unique number to identify the board. You can use this number in your program if you want to know which board is running your program.
|
|
10
|
+
|
|
11
|
+
## Returns
|
|
12
|
+
|
|
13
|
+
* a [buffer](/types/buffer) that contains a 64-bit value to uniquely identify this board.
|
|
14
|
+
|
|
15
|
+
## Example #example
|
|
16
|
+
|
|
17
|
+
Write the board's long serial number to the serial port as a Base64 string.
|
|
18
|
+
|
|
19
|
+
```blocks
|
|
20
|
+
console.log("serialnumber: " + control.deviceLongSerialNumber().toBase64())
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## See also #seealso
|
|
24
|
+
|
|
25
|
+
[device dal version](/reference/control/device-dal-version),
|
|
26
|
+
[device serial number](/reference/control/device-serial-number)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# constrain
|
|
2
|
+
|
|
3
|
+
Make certain that the value of a number you give is no smaller and no bigger than two other numbers.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
Math.constrain(0,0,0)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
A value is _constrained_, or limited, within a range by testing it's value against two limit numbers. One of the limit numbers sets the lowest value that the number tested should have. The other limit number sets the highest value that the number tested should have.
|
|
10
|
+
|
|
11
|
+
If the value tested is within the range of these two limit numbers, the value itself is returned. If the value is outside of the range of these two limit numbers, the value returned is one of the limit numbers that is closest to the value being tested.
|
|
12
|
+
|
|
13
|
+
So, if `15` is constrained within a range of `3` to `10`, then ``Math.constrain(15, 6, 10)`` will return `10`. Also, if `3` is constrained to the same range, ``Math.constrain(3, 6, 10)`` will return `6`. Of course, a value of `4` that is constrained by `3` to `10` stays as `4`.
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
* **value**: A [number](/types/number) that is tested to be in a range.
|
|
18
|
+
* **low**: the lower number limit of the range to test **value** for.
|
|
19
|
+
* **high**: the upper number limit of the range to test **value** for.
|
|
20
|
+
|
|
21
|
+
## Returns
|
|
22
|
+
|
|
23
|
+
* a [number](/types/number) that is a value constrained by the number range of **low** to **high**.
|
|
24
|
+
|
|
25
|
+
## Example #example
|
|
26
|
+
|
|
27
|
+
Keep a desired value within a realistic range of `50` to `100`.
|
|
28
|
+
|
|
29
|
+
```block
|
|
30
|
+
let desired = 155
|
|
31
|
+
let realistic = Math.constrain(desired, 50, 100)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## See also
|
|
35
|
+
|
|
36
|
+
[map](/reference/math/map)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# map
|
|
2
|
+
|
|
3
|
+
Convert a value in one number range to a value in another number range.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
Math.map(0, 0, 0, 0, 0)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
A _map_ is a conversion of one span of numbers to another. If a dog can live to 16 years and a person lives to 87 years, how do you make a 16 year life span seem like a 87 year life span? You say that one dog year is like some number of people years. This is a _mapping_ of dog years to people years.
|
|
10
|
+
|
|
11
|
+
Fahrenheit and Celsius are different ways to measure temperature. Celsius doesn't use the same amount of degrees as Fahrenheit. So, there is more energy in one degree of Celsius. If you want to convert a temperature value of Fahrenheit (something between freezing and boiling maybe) to Celsius, you can use ``Math.map(50, 32, 212, 0, 100)``. The map makes `50` degrees of Fahrenheit turn into `10` degrees of Celsius.
|
|
12
|
+
|
|
13
|
+
## Parameters
|
|
14
|
+
|
|
15
|
+
* **value**: a [number](/types/number) to convert from one range to another.
|
|
16
|
+
* **fromLow**: the low [number](/types/number) of the range to convert *from*.
|
|
17
|
+
* **fromHigh**: the high [number](/types/number) of the range to convert *from*
|
|
18
|
+
* **toLow**: the low [number](/types/number) of the range to convert *to*.
|
|
19
|
+
* **toHigh**: the high [number](/types/number) of the range to convert *to*.
|
|
20
|
+
|
|
21
|
+
## Returns
|
|
22
|
+
|
|
23
|
+
* a new value that is a [number](/types/number) converted from original **value** using a mapping of the **from** range into the **to** range.
|
|
24
|
+
|
|
25
|
+
# Example #example
|
|
26
|
+
|
|
27
|
+
Use a lifespan map to find out the age in "people years" of a dog that's `7` years old.
|
|
28
|
+
|
|
29
|
+
```block
|
|
30
|
+
let dogsAge = 7
|
|
31
|
+
let peoplesAge = Math.map(dogsAge, 1, 16, 15, 87)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## See also
|
|
35
|
+
|
|
36
|
+
[constrain](/reference/math/constrain)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# tile Hit From
|
|
2
|
+
|
|
3
|
+
Find out what type of tile a sprite has hit.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
scene.tileHitFrom(sprites.create(null), CollisionDirection.Left)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
If a sprite is contacting a wall tile, you can find out what kind of tile it is. The tile index in the tile map is returned.
|
|
10
|
+
|
|
11
|
+
## Parameters
|
|
12
|
+
|
|
13
|
+
* **direction**: the direction check for a wall collision: ``left``, ``right``, ``top``, or ``bottom``.
|
|
14
|
+
|
|
15
|
+
## Returns
|
|
16
|
+
|
|
17
|
+
* a [number](/types/number) which is the tile index for the wall tile contacting the sprite.
|
|
18
|
+
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
Build a brick wall of tiles in the scene. Send a arrow sprite towards the wall. When the sprite hits the wall, say what type of tile it contacted.
|
|
22
|
+
|
|
23
|
+
```blocks
|
|
24
|
+
let mySprite: Sprite = null
|
|
25
|
+
let flipImage: Image = null
|
|
26
|
+
scene.onHitTile(SpriteKind.Player, 2, function (sprite) {
|
|
27
|
+
sprite.say("tile: " + scene.tileHitFrom(sprite, CollisionDirection.Left))
|
|
28
|
+
})
|
|
29
|
+
scene.setTile(2, img`
|
|
30
|
+
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
|
31
|
+
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
|
|
32
|
+
1 2 2 2 2 2 2 2 2 2 2 2 2 f 2 1
|
|
33
|
+
1 2 2 f 2 2 2 2 2 2 2 2 2 2 2 1
|
|
34
|
+
1 2 2 2 2 2 2 f 2 2 2 2 2 2 2 1
|
|
35
|
+
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
|
|
36
|
+
1 2 2 2 2 2 2 2 2 2 2 2 f 2 2 1
|
|
37
|
+
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
|
|
38
|
+
1 2 2 2 2 f 2 2 2 f 2 2 2 2 2 1
|
|
39
|
+
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
|
|
40
|
+
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
|
|
41
|
+
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
|
|
42
|
+
1 2 2 f 2 2 2 2 2 2 2 2 f 2 2 1
|
|
43
|
+
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
|
|
44
|
+
1 2 2 2 2 2 2 f 2 2 2 2 f 2 2 1
|
|
45
|
+
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
|
|
46
|
+
`, true)
|
|
47
|
+
scene.setTileMap(img`
|
|
48
|
+
. . . . . . . . . .
|
|
49
|
+
. 2 . . . . . . . .
|
|
50
|
+
. 2 . . . . . . . .
|
|
51
|
+
. 2 . . . . . . . .
|
|
52
|
+
. 2 . . . . . . . .
|
|
53
|
+
. 2 . . . . . . . .
|
|
54
|
+
. 2 . . . . . . . .
|
|
55
|
+
. . . . . . . . . .
|
|
56
|
+
`)
|
|
57
|
+
flipImage = img`
|
|
58
|
+
. . . . . . . . . . . . . . . .
|
|
59
|
+
. . . . . . . . . . . . . . . .
|
|
60
|
+
. . . . . . . . . . . . . . . .
|
|
61
|
+
. . . . . 5 5 5 5 5 5 . . . . .
|
|
62
|
+
. . . 5 5 5 5 5 5 5 . . . . . .
|
|
63
|
+
. . 5 5 5 5 5 5 5 . . . . . . .
|
|
64
|
+
. 5 5 5 5 5 5 5 . . . . . . . .
|
|
65
|
+
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
|
|
66
|
+
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
|
|
67
|
+
. 5 5 5 5 5 5 5 . . . . . . . .
|
|
68
|
+
. . 5 5 5 5 5 5 5 . . . . . . .
|
|
69
|
+
. . . 5 5 5 5 5 5 5 . . . . . .
|
|
70
|
+
. . . . . 5 5 5 5 5 5 . . . . .
|
|
71
|
+
. . . . . . . . . . . . . . . .
|
|
72
|
+
. . . . . . . . . . . . . . . .
|
|
73
|
+
. . . . . . . . . . . . . . . .
|
|
74
|
+
`
|
|
75
|
+
mySprite = sprites.create(flipImage, SpriteKind.Player)
|
|
76
|
+
mySprite.vx = -50
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## See also #seealso
|
|
80
|
+
|
|
81
|
+
[on hit tile](/reference/scene/on-hit-tile)
|
|
@@ -110,7 +110,7 @@ namespace scene {
|
|
|
110
110
|
*/
|
|
111
111
|
//% blockId=legacyplaceontile block="on top of %tile=variables_get(myTile) place %sprite=variables_get(mySprite)"
|
|
112
112
|
//% group="Color-coded Tilemap"
|
|
113
|
-
//% help=
|
|
113
|
+
//% help=color-coded-tilemap/place
|
|
114
114
|
export function place(tile: tiles.Tile, mySprite: Sprite): void {
|
|
115
115
|
if (!tile) return;
|
|
116
116
|
tile.place(mySprite);
|
|
@@ -148,7 +148,7 @@ namespace scene {
|
|
|
148
148
|
*/
|
|
149
149
|
//% blockId=legacyspriteobstacle block="%sprite=variables_get(mySprite) wall hit on %direction"
|
|
150
150
|
//% group="Color-coded Tilemap"
|
|
151
|
-
//% help=
|
|
151
|
+
//% help=color-coded-tilemap/tile-hit-from
|
|
152
152
|
export function tileHitFrom(sprite: Sprite, direction: CollisionDirection): number {
|
|
153
153
|
if (!sprite) return 0;
|
|
154
154
|
return sprite.tileHitFrom(direction);
|
|
@@ -9066,7 +9066,7 @@ switch (step) {
|
|
|
9066
9066
|
return leave(s, r0)
|
|
9067
9067
|
default: oops()
|
|
9068
9068
|
} } }
|
|
9069
|
-
power_checkDeepSleep__P66135.info = {"start":
|
|
9069
|
+
power_checkDeepSleep__P66135.info = {"start":1084,"length":298,"line":36,"column":4,"endLine":46,"endColumn":5,"fileName":"pxt_modules/power/power.ts","functionName":"checkDeepSleep","argumentNames":[]}
|
|
9070
9070
|
|
|
9071
9071
|
function power_checkDeepSleep__P66135_mk(s) {
|
|
9072
9072
|
checkStack(s.depth);
|
|
@@ -9129,7 +9129,7 @@ switch (step) {
|
|
|
9129
9129
|
return leave(s, r0)
|
|
9130
9130
|
default: oops()
|
|
9131
9131
|
} } }
|
|
9132
|
-
power_init__P66137.info = {"start":
|
|
9132
|
+
power_init__P66137.info = {"start":1606,"length":376,"line":57,"column":4,"endLine":66,"endColumn":5,"fileName":"pxt_modules/power/power.ts","functionName":"init","argumentNames":[]}
|
|
9133
9133
|
|
|
9134
9134
|
function power_init__P66137_mk(s) {
|
|
9135
9135
|
checkStack(s.depth);
|
|
@@ -12607,7 +12607,7 @@ switch (step) {
|
|
|
12607
12607
|
return leave(s, r0)
|
|
12608
12608
|
default: oops()
|
|
12609
12609
|
} } }
|
|
12610
|
-
power_poke__P66134.info = {"start":
|
|
12610
|
+
power_poke__P66134.info = {"start":793,"length":81,"line":26,"column":4,"endLine":29,"endColumn":5,"fileName":"pxt_modules/power/power.ts","functionName":"poke","argumentNames":[]}
|
|
12611
12611
|
|
|
12612
12612
|
function power_poke__P66134_mk(s) {
|
|
12613
12613
|
checkStack(s.depth);
|
|
@@ -8959,7 +8959,7 @@ switch (step) {
|
|
|
8959
8959
|
return leave(s, r0)
|
|
8960
8960
|
default: oops()
|
|
8961
8961
|
} } }
|
|
8962
|
-
power_checkDeepSleep__P83034.info = {"start":
|
|
8962
|
+
power_checkDeepSleep__P83034.info = {"start":1084,"length":298,"line":36,"column":4,"endLine":46,"endColumn":5,"fileName":"pxt_modules/power/power.ts","functionName":"checkDeepSleep","argumentNames":[]}
|
|
8963
8963
|
|
|
8964
8964
|
function power_checkDeepSleep__P83034_mk(s) {
|
|
8965
8965
|
checkStack(s.depth);
|
|
@@ -9022,7 +9022,7 @@ switch (step) {
|
|
|
9022
9022
|
return leave(s, r0)
|
|
9023
9023
|
default: oops()
|
|
9024
9024
|
} } }
|
|
9025
|
-
power_init__P83036.info = {"start":
|
|
9025
|
+
power_init__P83036.info = {"start":1606,"length":376,"line":57,"column":4,"endLine":66,"endColumn":5,"fileName":"pxt_modules/power/power.ts","functionName":"init","argumentNames":[]}
|
|
9026
9026
|
|
|
9027
9027
|
function power_init__P83036_mk(s) {
|
|
9028
9028
|
checkStack(s.depth);
|
|
@@ -12500,7 +12500,7 @@ switch (step) {
|
|
|
12500
12500
|
return leave(s, r0)
|
|
12501
12501
|
default: oops()
|
|
12502
12502
|
} } }
|
|
12503
|
-
power_poke__P83033.info = {"start":
|
|
12503
|
+
power_poke__P83033.info = {"start":793,"length":81,"line":26,"column":4,"endLine":29,"endColumn":5,"fileName":"pxt_modules/power/power.ts","functionName":"poke","argumentNames":[]}
|
|
12504
12504
|
|
|
12505
12505
|
function power_poke__P83033_mk(s) {
|
|
12506
12506
|
checkStack(s.depth);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# device Dal Version
|
|
2
|
+
|
|
3
|
+
Get the version information for the system software on the @boardname@.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
control.deviceDalVersion()
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Returns
|
|
10
|
+
|
|
11
|
+
* a [string](/types/string) that represents the version of the system software (DAL) on the board.
|
|
12
|
+
|
|
13
|
+
Returns `"sim"` when running the simulator, and `"linux"` when running on Raspberry Pi.
|
|
14
|
+
|
|
15
|
+
## Example #example
|
|
16
|
+
|
|
17
|
+
Write the system software version to the serial port.
|
|
18
|
+
|
|
19
|
+
```blocks
|
|
20
|
+
serial.writeLine("DAL version = " + control.deviceDalVersion());
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## See also #seealso
|
|
24
|
+
|
|
25
|
+
[device serial number](/reference/control/device-serial-number)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# millis
|
|
2
|
+
|
|
3
|
+
Get the number of milliseconds of time passed since the board was turned on or last reset.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
control.millis()
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Returns
|
|
10
|
+
|
|
11
|
+
* the [number](/types/number) of milliseconds of time since the board was reset.
|
|
12
|
+
|
|
13
|
+
## Example #example
|
|
14
|
+
|
|
15
|
+
Find how many days, hours, minutes, and seconds the @boardname@ has been running.
|
|
16
|
+
|
|
17
|
+
```blocks
|
|
18
|
+
let msecs = control.millis()
|
|
19
|
+
let seconds = msecs / 1000
|
|
20
|
+
let mins = seconds / 60
|
|
21
|
+
let hours = mins / 60
|
|
22
|
+
let days = hours / 24
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## #seealso
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# pause Until
|
|
2
|
+
|
|
3
|
+
Pause a part of the program for some number of milliseconds.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
control.pause(400)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
When code in a block comes to a ``||control:pause until||``, it will wait the amount of time you tell it to. Code
|
|
10
|
+
in blocks like ``||loops:forever||`` and ``||control:run in parallel||`` will keep running while code in some other
|
|
11
|
+
block is waiting at a ``||control:pause||``.
|
|
12
|
+
|
|
13
|
+
## Parameters
|
|
14
|
+
|
|
15
|
+
* **ms**: the [number](/types/number) of milliseconds that you want to pause for. So, 100 milliseconds = 1/10 second, and 1000 milliseconds = 1 second.
|
|
16
|
+
|
|
17
|
+
## Example #example
|
|
18
|
+
|
|
19
|
+
Write the first five natural numbers to the console but wait one-half second between each write.
|
|
20
|
+
|
|
21
|
+
```blocks
|
|
22
|
+
for (let i = 0; i < 5; i++) {
|
|
23
|
+
console.logValue("naturals", i + 1)
|
|
24
|
+
control.pauseUntil(500)
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## See also #seealso
|
|
29
|
+
|
|
30
|
+
[while](/blocks/loops/while), [for](/blocks/loops/for),
|
|
31
|
+
[forever](/reference/loops/forever)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# raise Event
|
|
2
|
+
|
|
3
|
+
Announce that something happened at an event source.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
control.raiseEvent(0, 0)
|
|
7
|
+
```
|
|
8
|
+
You use ``||control:raise event||`` to announce that something happened with the board or something special
|
|
9
|
+
happened in your program. You do this if there are other parts of your program that might want
|
|
10
|
+
to know about it.
|
|
11
|
+
|
|
12
|
+
If you've added some [``||control:on event||``](/reference/control/on-event) blocks to your program,
|
|
13
|
+
the code inside them will run if the **src** and **value** numbers are the same as those with
|
|
14
|
+
``||control:raise event||``. The **src** tells about where the event is coming from. You pick a number
|
|
15
|
+
for it to identify something like a sensor or a special situation in your program. If you want
|
|
16
|
+
to announce that it's getting dark, you can make **src** something like `51` for the light sensor's
|
|
17
|
+
source number. This means that anything you want to announce about the light sensor, you raise
|
|
18
|
+
event with `51`.
|
|
19
|
+
|
|
20
|
+
Many events can happen to a single source (**src**). With the light sensor you can announce that
|
|
21
|
+
its getting darker or lighter. This is the cause of the event, the **value**. So, for the light
|
|
22
|
+
sensor (the source number `51`) you might add two events for **value**: `1` for darker and `2` for lighter.
|
|
23
|
+
|
|
24
|
+
With the light sensor example, you tell the program that it's getting darker:
|
|
25
|
+
|
|
26
|
+
```block
|
|
27
|
+
control.raiseEvent(51, 1)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Parameters
|
|
31
|
+
|
|
32
|
+
* **src**: the identification [number](/types/number) (the source) of this event, such as: `10`.
|
|
33
|
+
* **value**: a [number](/types/number) tells what the cause of the event is, like: `4`.
|
|
34
|
+
|
|
35
|
+
## Example #example
|
|
36
|
+
|
|
37
|
+
Register two events coming from source `22`. Write to the console when
|
|
38
|
+
the events of `0` and `1` are _raised_.
|
|
39
|
+
|
|
40
|
+
```blocks
|
|
41
|
+
const myNotify = 22;
|
|
42
|
+
|
|
43
|
+
control.runInParallel(function() {
|
|
44
|
+
for (let i = 0; i < 2; i++) {
|
|
45
|
+
pause(1000);
|
|
46
|
+
control.raiseEvent(myNotify, i);
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
control.onEvent(myNotify, 0, () => {
|
|
51
|
+
console.logValue("myNotify", 0)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
control.onEvent(myNotify, 1, () => {
|
|
55
|
+
console.logValue("myNotify", 1)
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## See also #seealso
|
|
60
|
+
|
|
61
|
+
[on event](/reference/control/on-event), [wait for event](/reference/control/wait-for-event)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# reset
|
|
2
|
+
|
|
3
|
+
Reset the board and start the program from the beginning.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
control.reset()
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Everything that the program did with the board is set back to the way it was before the
|
|
10
|
+
program started. The program starts over again from the beginning.
|
|
11
|
+
|
|
12
|
+
## Example #example
|
|
13
|
+
|
|
14
|
+
Reset the board and begin again.
|
|
15
|
+
|
|
16
|
+
```blocks
|
|
17
|
+
control.reset()
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## #seealso
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# millis
|
|
2
|
+
|
|
3
|
+
Get the number of seconds of time passed since the board was turned on or last reset.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
control.seconds()
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Returns
|
|
10
|
+
|
|
11
|
+
* the [number](/types/number) of seconds of time since the board was reset.
|
|
12
|
+
|
|
13
|
+
## Example #example
|
|
14
|
+
|
|
15
|
+
Find how many days, hours, minutes, and seconds the @boardname@ has been running.
|
|
16
|
+
|
|
17
|
+
```blocks
|
|
18
|
+
let seconds = control.seconds()
|
|
19
|
+
let mins = seconds / 60
|
|
20
|
+
let hours = mins / 60
|
|
21
|
+
let days = hours / 24
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## #seealso
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Control
|
|
2
|
+
|
|
3
|
+
Program controls and events.
|
|
4
|
+
|
|
5
|
+
```cards
|
|
6
|
+
control.millis()
|
|
7
|
+
control.seconds()
|
|
8
|
+
control.reset()
|
|
9
|
+
control.deviceSerialNumber()
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Advanced #advanced
|
|
13
|
+
|
|
14
|
+
```cards
|
|
15
|
+
control.raiseEvent(0, 0)
|
|
16
|
+
control.deviceDalVersion()
|
|
17
|
+
```
|
package/libs/core/timer.ts
CHANGED
|
@@ -14,6 +14,7 @@ namespace control {
|
|
|
14
14
|
* Gets the elapsed time in millis since the last reset
|
|
15
15
|
*/
|
|
16
16
|
//% blockId=timerMillis block="%timer|millis"
|
|
17
|
+
//% help=control/millis
|
|
17
18
|
millis(): number {
|
|
18
19
|
return control.millis() - this.start;
|
|
19
20
|
}
|
|
@@ -22,6 +23,7 @@ namespace control {
|
|
|
22
23
|
* Gets the elapsed time in seconds since the last reset
|
|
23
24
|
*/
|
|
24
25
|
//% blockId=timerSeconds block="%timer|seconds"
|
|
26
|
+
//% help=control/seconds
|
|
25
27
|
seconds(): number {
|
|
26
28
|
return this.millis() / 1000;
|
|
27
29
|
}
|
|
@@ -30,6 +32,7 @@ namespace control {
|
|
|
30
32
|
* Resets the timer
|
|
31
33
|
*/
|
|
32
34
|
//% blockId=timerRest block="%timer|reset"
|
|
35
|
+
//% help=control/reset
|
|
33
36
|
reset() {
|
|
34
37
|
this.start = control.millis();
|
|
35
38
|
}
|
|
@@ -39,6 +42,7 @@ namespace control {
|
|
|
39
42
|
* @param ms how long to pause for, eg: 5, 100, 200, 500, 1000, 2000
|
|
40
43
|
*/
|
|
41
44
|
//% blockId=timerPauseUntil block="%timer|pause until (ms) %ms"
|
|
45
|
+
//% help=control/pause-until
|
|
42
46
|
pauseUntil(ms: number) {
|
|
43
47
|
const remaining = this.millis() - ms;
|
|
44
48
|
pause(Math.max(0, remaining));
|
|
@@ -98,6 +98,8 @@ declare const enum DAL {
|
|
|
98
98
|
CFG_PIN_WIFI_AT_TX = 91,
|
|
99
99
|
CFG_PIN_WIFI_AT_RX = 92,
|
|
100
100
|
CFG_PIN_USB_POWER = 93,
|
|
101
|
+
CFG_SETTINGS_SIZE_DEFL = 95,
|
|
102
|
+
CFG_SETTINGS_SIZE = 96,
|
|
101
103
|
ACCELEROMETER_TYPE_LIS3DH = 50,
|
|
102
104
|
ACCELEROMETER_TYPE_LIS3DH_ALT = 48,
|
|
103
105
|
ACCELEROMETER_TYPE_MMA8453 = 56,
|
|
@@ -98,6 +98,8 @@ declare const enum DAL {
|
|
|
98
98
|
CFG_PIN_WIFI_AT_TX = 91,
|
|
99
99
|
CFG_PIN_WIFI_AT_RX = 92,
|
|
100
100
|
CFG_PIN_USB_POWER = 93,
|
|
101
|
+
CFG_SETTINGS_SIZE_DEFL = 95,
|
|
102
|
+
CFG_SETTINGS_SIZE = 96,
|
|
101
103
|
ACCELEROMETER_TYPE_LIS3DH = 50,
|
|
102
104
|
ACCELEROMETER_TYPE_LIS3DH_ALT = 48,
|
|
103
105
|
ACCELEROMETER_TYPE_MMA8453 = 56,
|
|
@@ -7524,7 +7524,7 @@ switch (step) {
|
|
|
7524
7524
|
return leave(s, r0)
|
|
7525
7525
|
default: oops()
|
|
7526
7526
|
} } }
|
|
7527
|
-
power_checkDeepSleep__P143656.info = {"start":
|
|
7527
|
+
power_checkDeepSleep__P143656.info = {"start":1084,"length":298,"line":36,"column":4,"endLine":46,"endColumn":5,"fileName":"pxt_modules/power/power.ts","functionName":"checkDeepSleep","argumentNames":[]}
|
|
7528
7528
|
|
|
7529
7529
|
function power_checkDeepSleep__P143656_mk(s) {
|
|
7530
7530
|
checkStack(s.depth);
|
|
@@ -7587,7 +7587,7 @@ switch (step) {
|
|
|
7587
7587
|
return leave(s, r0)
|
|
7588
7588
|
default: oops()
|
|
7589
7589
|
} } }
|
|
7590
|
-
power_init__P143658.info = {"start":
|
|
7590
|
+
power_init__P143658.info = {"start":1606,"length":376,"line":57,"column":4,"endLine":66,"endColumn":5,"fileName":"pxt_modules/power/power.ts","functionName":"init","argumentNames":[]}
|
|
7591
7591
|
|
|
7592
7592
|
function power_init__P143658_mk(s) {
|
|
7593
7593
|
checkStack(s.depth);
|
|
@@ -11999,7 +11999,7 @@ switch (step) {
|
|
|
11999
11999
|
return leave(s, r0)
|
|
12000
12000
|
default: oops()
|
|
12001
12001
|
} } }
|
|
12002
|
-
power_poke__P143655.info = {"start":
|
|
12002
|
+
power_poke__P143655.info = {"start":793,"length":81,"line":26,"column":4,"endLine":29,"endColumn":5,"fileName":"pxt_modules/power/power.ts","functionName":"poke","argumentNames":[]}
|
|
12003
12003
|
|
|
12004
12004
|
function power_poke__P143655_mk(s) {
|
|
12005
12005
|
checkStack(s.depth);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# runtime
|
|
2
|
+
|
|
3
|
+
Get the time since the game was started in milliseconds.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
game.runtime()
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Returns
|
|
10
|
+
|
|
11
|
+
* a [number](/types/number) that is the amount of time the game has run for.
|
|
12
|
+
|
|
13
|
+
## Example #example
|
|
14
|
+
|
|
15
|
+
Give a sprite warning message when the game runtime is greater that `15` minutes.
|
|
16
|
+
|
|
17
|
+
```blocks
|
|
18
|
+
info.startCountdown(30)
|
|
19
|
+
let mySprite = sprites.create(img`
|
|
20
|
+
. . . . . . . . . . . . . . . .
|
|
21
|
+
. . 4 4 4 . . . . 4 4 4 . . . .
|
|
22
|
+
. 4 5 5 5 e . . e 5 5 5 4 . . .
|
|
23
|
+
4 5 5 5 5 5 e e 5 5 5 5 5 4 . .
|
|
24
|
+
4 5 5 4 4 5 5 5 5 4 4 5 5 4 . .
|
|
25
|
+
e 5 4 4 5 5 5 5 5 5 4 4 5 e . .
|
|
26
|
+
. e e 5 5 5 5 5 5 5 5 e e . . .
|
|
27
|
+
. . e 5 f 5 5 5 5 f 5 e . . . .
|
|
28
|
+
. . f 5 5 5 4 4 5 5 5 f . f f .
|
|
29
|
+
. . . 4 5 5 f f 5 5 6 f f 5 f .
|
|
30
|
+
. . . f 6 6 6 6 6 6 4 f 5 5 f .
|
|
31
|
+
. . . f 5 5 5 5 5 5 5 4 5 f . .
|
|
32
|
+
. . . . f 5 4 5 f 5 f f f . . .
|
|
33
|
+
. . . . . f f f f f f f . . . .
|
|
34
|
+
`, SpriteKind.Player)
|
|
35
|
+
game.onUpdateInterval(5000, function () {
|
|
36
|
+
if (game.runtime() > (1000 * 60 * 15)) {
|
|
37
|
+
mySprite.sayText("Time to quit!")
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## See also #seealso
|
|
43
|
+
|
|
44
|
+
[start countdown](/reference/info/start-countdown),
|
|
45
|
+
[change countdown by](/reference/info/change-countdown-by),
|
|
46
|
+
[on countdown end](/reference/info/on-countdown-end)
|
|
@@ -23,6 +23,7 @@ namespace light {
|
|
|
23
23
|
*/
|
|
24
24
|
//% blockId="builtinlightsetgradient" block="set gradient from %startRgb=colorNumberPicker to %endRgb=colorNumberPicker"
|
|
25
25
|
//% weight=78 blockGap=8 blockHidden=true
|
|
26
|
+
//% help=light/neopixelstrip/set-gradient
|
|
26
27
|
export function setGradient(startRgb: number, endRgb: number) {
|
|
27
28
|
light.pixels.setGradient(startRgb, endRgb);
|
|
28
29
|
}
|