pxt-microbit 4.1.4 → 4.1.8

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.
Files changed (58) hide show
  1. package/built/common-sim.d.ts +51 -2
  2. package/built/common-sim.js +296 -6
  3. package/built/hexcache/{6526a3337377701ca7bf1d9940f76fdccac145405380ee3ecc2c96f6049e34ce.hex → 0a7e07c684763d50c302169904fdbb9fc387e1f105f5c8a62f369eab7e443b53.hex} +9 -9
  4. package/built/hexcache/{8fc8a1499d69a5d8cc851cf49d16112b3021ab801238204dacf84073acf90e7c.hex → 13247a2921d73de268c2d92a591f952d610020f3c1938dde251c0139d1823417.hex} +9 -9
  5. package/built/hexcache/3237486a484d0d476c16429f4d524f5d3e2b2fd99336859f0cbb588ceb17e16b.hex +14849 -0
  6. package/built/hexcache/72b9e94993590d9bbc5283b9e11d7f3a19235783f6a54231bf9cc657c64d7bc1.hex +14318 -0
  7. package/built/sim-strings.json +3 -3
  8. package/built/sim.js +10 -12
  9. package/built/target-strings.json +2 -1
  10. package/built/target.js +117 -46
  11. package/built/target.json +117 -46
  12. package/built/targetlight.json +5 -5
  13. package/built/web/blockly.css +1 -1
  14. package/built/web/rtlblockly.css +1 -1
  15. package/built/web/rtlsemantic.css +16 -16
  16. package/built/web/semantic.css +16 -16
  17. package/docs/blocks/comments.md +131 -0
  18. package/docs/blocks/loops.md +12 -0
  19. package/docs/device/usb/webusb.md +31 -9
  20. package/docs/device/usb/windows-chrome.md +14 -24
  21. package/docs/device/usb/windows-edge.md +11 -13
  22. package/docs/device/usb.md +10 -4
  23. package/docs/device.md +28 -12
  24. package/docs/docs.md +1 -1
  25. package/docs/extensions.md +126 -2
  26. package/docs/projects/SUMMARY.md +7 -1
  27. package/docs/projects/micro-chat.md +8 -8
  28. package/docs/projects/mood-radio.md +3 -1
  29. package/docs/projects/multi-dice.md +8 -6
  30. package/docs/projects/plot-acceleration.md +2 -2
  31. package/docs/projects/v2-blow-away.md +317 -0
  32. package/docs/projects/v2-clap-lights.md +195 -0
  33. package/docs/projects/v2-countdown.md +151 -0
  34. package/docs/projects/v2-morse-chat.md +297 -0
  35. package/docs/projects/v2-pet-hamster.md +165 -0
  36. package/docs/projects.md +8 -2
  37. package/docs/reference/basic/forever.md +17 -4
  38. package/docs/reference/basic/show-number.md +1 -1
  39. package/docs/reference/game/change.md +10 -6
  40. package/docs/reference/game/get.md +6 -6
  41. package/docs/reference/game/set.md +29 -12
  42. package/docs/reference/loops/every-interval.md +42 -0
  43. package/docs/reference/radio/on-received-buffer.md +1 -0
  44. package/docs/reference/radio/on-received-number.md +2 -0
  45. package/docs/reference/radio/on-received-string.md +1 -0
  46. package/docs/reference/radio/on-received-value.md +1 -0
  47. package/docs/reference/radio/received-packet.md +1 -0
  48. package/docs/reference/radio/send-buffer.md +1 -0
  49. package/docs/reference/radio/send-string.md +1 -0
  50. package/docs/reference/radio/set-group.md +8 -0
  51. package/docs/reference/radio/write-received-packet-to-serial.md +1 -0
  52. package/docs/reference/radio/write-value-to-serial.md +1 -0
  53. package/docs/tutorials-v2.md +39 -0
  54. package/package.json +5 -5
  55. package/sim/public/icons/jacdac.svg +1 -1
  56. package/targetconfig.json +49 -9
  57. package/built/hexcache/02e34856c566087a1e5f0212e31686199c414ee7c8a2b9c36be7167d71548860.hex +0 -13960
  58. package/built/hexcache/447fa4d5b24ea1ca19eab3745af559cd49d5831ea3e3d6750812b3af3de0f2c4.hex +0 -14499
@@ -55,6 +55,10 @@ Check out [the accessories pages on microbit.org](https://microbit.org/buy/acces
55
55
  "name": "Wearables",
56
56
  "url": "/extensions#wearables",
57
57
  "cardType": "link"
58
+ }, {
59
+ "name": "Utilities",
60
+ "url": "/extensions#utilities",
61
+ "cardType": "link"
58
62
  }]
59
63
  ```
60
64
 
@@ -62,6 +66,18 @@ Check out [the accessories pages on microbit.org](https://microbit.org/buy/acces
62
66
 
63
67
  ```codecard
64
68
  [{
69
+ "name": "Joy-IT RB-TFT1.8",
70
+ "url": "/pkg/joy-it/pxt-RB-TFT1.8",
71
+ "cardType": "package"
72
+ }, {
73
+ "name": "Kitronik 128x64 Display",
74
+ "url": "/pkg/KitronikLtd/pxt-kitronik-128x64Display",
75
+ "cardType": "package"
76
+ }, {
77
+ "name": "Monk Makes 7-Segment",
78
+ "url": "/pkg/monkmakes/monkmakes-7-segment",
79
+ "cardType": "package"
80
+ }, {
65
81
  "name": "Pimoroni inky:bit",
66
82
  "url": "/pkg/pimoroni/pxt-inkybit",
67
83
  "cardType": "package"
@@ -118,6 +134,10 @@ Check out [the accessories pages on microbit.org](https://microbit.org/buy/acces
118
134
 
119
135
  ```codecard
120
136
  [{
137
+ "name": "Kittenbot JoyFrog",
138
+ "url":"/pkg/KittenBot/pxt-joyfrog",
139
+ "cardType": "package"
140
+ }, {
121
141
  "name": "Elecfreaks magic wand",
122
142
  "url":"/pkg/elecfreaks/pxt-magicwand",
123
143
  "cardType": "package"
@@ -156,6 +176,14 @@ Check out [the accessories pages on microbit.org](https://microbit.org/buy/acces
156
176
 
157
177
  ```codecard
158
178
  [{
179
+ "name": "SGBotic Ultimate SR04",
180
+ "url":"/pkg/SGBotic/pxt-SGBotic-Ultimate-SR04-RGB",
181
+ "cardType": "package"
182
+ }, {
183
+ "name": "TCS3200 Color sensor",
184
+ "url":"/pkg/joy-it/pxt-SEN-Color",
185
+ "cardType": "package"
186
+ }, {
159
187
  "name": "MPU6050 Gyroscope",
160
188
  "url":"/pkg/joy-it/SEN-MPU6050",
161
189
  "cardType": "package"
@@ -282,6 +310,18 @@ Check out [the accessories pages on microbit.org](https://microbit.org/buy/acces
282
310
 
283
311
  ```codecard
284
312
  [{
313
+ "name": "iClass IoT",
314
+ "url":"/pkg/KelieLeung/pxt-iClassIoT",
315
+ "cardType": "package"
316
+ }, {
317
+ "name": "Kittenbot Wifi",
318
+ "url":"/pkg/KittenBot/pxt-kittenwifi",
319
+ "cardType": "package"
320
+ }, {
321
+ "name": "ESP8266 AT",
322
+ "url":"/pkg/CytronTechnologies/pxt-esp8266",
323
+ "cardType": "package"
324
+ }, {
285
325
  "name": "Wappsto:bit",
286
326
  "url":"/pkg/Wappsto/pxt-wappsto",
287
327
  "cardType": "package"
@@ -316,9 +356,29 @@ Check out [the accessories pages on microbit.org](https://microbit.org/buy/acces
316
356
 
317
357
  ```codecard
318
358
  [{
359
+ "name": "HacKids hack:bit",
360
+ "url": "/pkg/HackidsEdu/pxt-hackbit",
361
+ "cardType": "package"
362
+ }, {
363
+ "name": "KittenBot Sugar",
364
+ "url": "/pkg/KittenBot/pxt-sugar",
365
+ "cardType": "package"
366
+ }, {
367
+ "name": "KittenBot Powerbrick",
368
+ "url": "/pkg/KittenBot/pxt-powerbrick",
369
+ "cardType": "package"
370
+ }, {
371
+ "name": "Kitronik LAB:bit",
372
+ "url": "/pkg/KitronikLtd/pxt-kitronik-lab-bit",
373
+ "cardType": "package"
374
+ }, {
319
375
  "name": "PT-BOT PTKidsBIT",
320
376
  "url": "/pkg/iBuilds/pxt-PTKidsBIT",
321
377
  "cardType": "package"
378
+ }, {
379
+ "name": "Stemhub City",
380
+ "url": "/pkg/stemhub/pxt-StemhubCity",
381
+ "cardType": "package"
322
382
  }, {
323
383
  "name": "Pi Supply tinker:kit",
324
384
  "url": "/pkg/PiSupply/pxt-tinker-kit",
@@ -332,8 +392,12 @@ Check out [the accessories pages on microbit.org](https://microbit.org/buy/acces
332
392
  "url":"/pkg/elecfreaks/pxt-PlanetX",
333
393
  "cardType": "package"
334
394
  }, {
335
- "name": "Inksmith Climate Action Kit",
336
- "url":"/pkg/dugbraden/pxt-climate-action-kit",
395
+ "name": "Inksmith Climate Action Kit: Land",
396
+ "url":"/pkg/climate-action-kits/pxt-climate-action-kit-land",
397
+ "cardType": "package"
398
+ }, {
399
+ "name": "Inksmith Climate Action Kit: Energy",
400
+ "url":"/pkg/climate-action-kits/pxt-climate-action-kit-land",
337
401
  "cardType": "package"
338
402
  }, {
339
403
  "name": "Grove inventor kit",
@@ -388,6 +452,14 @@ Check out [the accessories pages on microbit.org](https://microbit.org/buy/acces
388
452
 
389
453
  ```codecard
390
454
  [{
455
+ "name": "KittenBot KOI AI module ",
456
+ "url":"/pkg/KittenBot/pxt-koi",
457
+ "cardType": "package"
458
+ }, {
459
+ "name": "Elecfreaks Smart AI Lens ",
460
+ "url":"/pkg/elecfreaks/pxt-PlanetX-AI",
461
+ "cardType": "package"
462
+ }, {
391
463
  "name": "MU Vision camera",
392
464
  "url":"/pkg/mu-opensource/pxt-muvision",
393
465
  "cardType": "package"
@@ -401,9 +473,37 @@ Check out [the accessories pages on microbit.org](https://microbit.org/buy/acces
401
473
 
402
474
  ```codecard
403
475
  [{
476
+ "name": "Kittenbot miniLFR",
477
+ "url":"/pkg/KittenBot/pxt-minilfr",
478
+ "cardType": "package"
479
+ }, {
480
+ "name": "Cytron ZOOM:BIT",
481
+ "url":"/pkg/CytronTechnologies/pxt-zoombit",
482
+ "cardType": "package"
483
+ }, {
484
+ "name": "Kid Spark Spark:bit",
485
+ "url":"/pkg/KidSpark/pxt-sparkbit",
486
+ "cardType": "package"
487
+ }, {
488
+ "name": "BPI TriodeCar",
489
+ "url":"/pkg/BPI-STEAM/pxt-triodecar",
490
+ "cardType": "package"
491
+ }, {
492
+ "name": "ArtecRobo Kit",
493
+ "url":"/pkg/artec-kk/pxt-artecrobo-kit",
494
+ "cardType": "package"
495
+ }, {
496
+ "name": "Elecfreaks DRONE:BIT",
497
+ "url":"/pkg/elecfreaks/pxt-Dronebit/",
498
+ "cardType": "package"
499
+ }, {
404
500
  "name": "MakeKit Hoverbit",
405
501
  "url":"/pkg/gomakekit/Hoverbit_V2",
406
502
  "cardType": "package"
503
+ }, {
504
+ "name": "Stemhubbit car",
505
+ "url":"/pkg/stemhub/pxt-Stemhubbit",
506
+ "cardType": "package"
407
507
  }, {
408
508
  "name": "MATRIX Micro",
409
509
  "url":"/pkg/pxt-MatrixMicro",
@@ -615,6 +715,14 @@ Check out [the accessories pages on microbit.org](https://microbit.org/buy/acces
615
715
 
616
716
  ```codecard
617
717
  [{
718
+ "name": "PT-BOT KidsBIT",
719
+ "url":"/pkg/iBuilds/pxt-PTKidsBIT-IoT",
720
+ "cardType": "package"
721
+ }, {
722
+ "name": "Kitronik Air Quality & Environmental Board",
723
+ "url":"/pkg/KitronikLtd/pxt-kitronik-air-quality",
724
+ "cardType": "package"
725
+ }, {
618
726
  "name": "DFRobot Natural Science Board",
619
727
  "url":"/pkg/DFRobot/pxt-DFRobot-NaturalScience",
620
728
  "cardType": "package"
@@ -732,6 +840,22 @@ Check out [the accessories pages on microbit.org](https://microbit.org/buy/acces
732
840
  ## Utilities
733
841
  ```codecard
734
842
  [{
843
+ "name": "Lego PF trasmitter",
844
+ "url":"/pkg/aorczyk/lego-pf-transmitter",
845
+ "cardType": "package"
846
+ }, {
847
+ "name": "Kodely dot",
848
+ "url":"/pkg/Kodely-io/dot",
849
+ "cardType": "package"
850
+ }, {
851
+ "name": "Wait until...",
852
+ "url":"/pkg/TeacherPinky/Wait-Until-Blocks",
853
+ "cardType": "package"
854
+ }, {
855
+ "name": "micro:bit power saving",
856
+ "url":"/pkg/microbit-foundation/pxt-microbit-v2-power",
857
+ "cardType": "package"
858
+ }, {
735
859
  "name": "DS3231 Real Time Clock",
736
860
  "url":"/pkg/AlexandreFrolov/DS3231",
737
861
  "cardType": "package"
@@ -7,6 +7,12 @@
7
7
  * [Dice](/projects/dice)
8
8
  * [Love Meter](/projects/love-meter)
9
9
  * [Micro Chat](/projects/micro-chat)
10
+ * [Tutorials for the new micro:bit (V2)](/tutorials-v2)
11
+ * [Pet Hamster](/projects/v2-pet-hamster)
12
+ * [Countdown](/projects/v2-countdown)
13
+ * [Morse Chat](/projects/v2-morse-chat)
14
+ * [Clap Lights](/projects/v2-clap-lights)
15
+ * [Blow Away](/projects/v2-blow-away)
10
16
  * [Live Coding](/live-coding)
11
17
  * [Flashing Heart](https://youtu.be/NvEOKZ8wh9s)
12
18
  * [Name Tag](https://youtu.be/xpRI5jjQ31E)
@@ -106,7 +112,7 @@
106
112
  * [Square](/projects/turtle-square)
107
113
  * [Spiral](/projects/turtle-spiral)
108
114
  * [Scanner](/projects/turtle-scanner)
109
- * [Blocks To JavaScript](/courses/blocks-to-javascript)
115
+ * [Blocks to JavaScript](/courses/blocks-to-javascript)
110
116
  * [Hello JavaScript](/courses/blocks-to-javascript/hello-javascript)
111
117
  * [Starter Blocks](/courses/blocks-to-javascript/starter-blocks)
112
118
  * [Writing Code](/courses/blocks-to-javascript/writing-code)
@@ -6,6 +6,14 @@
6
6
 
7
7
  Use the **radio** to send and receive messages with other @boardname@.
8
8
 
9
+ ## Set a radio group
10
+
11
+ The first thing you want to do is to put in a ``||radio:set group||``. This will make certain that you and another @boardname@ will receive just the messages assigned to that group and not the messages sent from some other @boardname@ that's not part of your conversation. This like tuning to a particular channel to talk on.
12
+
13
+ ```blocks
14
+ radio.setGroup(1)
15
+ ```
16
+
9
17
  ## Sending a message
10
18
 
11
19
  Use ``||input:on button pressed||`` to send a text message over radio with ``||radio:send string||``.
@@ -53,14 +61,6 @@ radio.onReceivedString(function (receivedString) {
53
61
 
54
62
  If you have two @boardname@s, download the program to each one. Press button **A** on one and see if the other gets a message.
55
63
 
56
- ## Groups
57
-
58
- Use the ``||radio:set group||`` block to assign a **group** number to your program. You will only receive messages from @boardname@s within the same group. Use this to avoid receiving messages from every @boardname@ that is transmitting.
59
-
60
- ```blocks
61
- radio.setGroup(123)
62
- ```
63
-
64
64
  ```package
65
65
  radio
66
66
  ```
@@ -15,6 +15,7 @@ between @boardname@s using the radio antenna, just like a phone can send text me
15
15
  Let's add blocks that send a number when button ``A`` is pressed. We assume that `0` is the "mood code" to send for **smiley**.
16
16
 
17
17
  ```blocks
18
+ radio.setGroup(1)
18
19
  input.onButtonPressed(Button.A, () => {
19
20
  radio.sendNumber(0)
20
21
  basic.showIcon(IconNames.Happy)
@@ -65,9 +66,10 @@ That's it. Download your code to multiple @boardname@s and try it out!
65
66
 
66
67
  Try adding a new code and use the ``||input:on shake||`` event to send it.
67
68
 
68
- ## Full sources
69
+ ## Complete program
69
70
 
70
71
  ```blocks
72
+ radio.setGroup(1)
71
73
  input.onButtonPressed(Button.A, () => {
72
74
  radio.sendNumber(0)
73
75
  basic.showIcon(IconNames.Happy)
@@ -22,9 +22,9 @@ input.onGesture(Gesture.Shake, function () {
22
22
 
23
23
  We need to store the result of the dice cast in a variable. A **variable** is like a place in the memory of the @boardname@ where you save information, like numbers.
24
24
 
25
- * Go to the **Variables** toolbox and click ``||Make a Variable||`` to create a new variable. We will call it **dice**.
26
- * Add a ``||set dice to||`` block and drag the ``||pick random||`` into it.
27
- * Drag a ``||dice||`` from the **Variables** toolbox into the ``||basic:show number||`` block.
25
+ * Go to the **Variables** toolbox and click ``Make a Variable`` to create a new variable. We will call it **dice**.
26
+ * Add a ``||variables:set dice to||`` block and drag the ``||math:pick random||`` into it.
27
+ * Drag a ``||variables:dice||`` variable from the **Variables** toolbox into the ``||basic:show number||`` block.
28
28
 
29
29
  ```blocks
30
30
  let dice = 0
@@ -36,9 +36,10 @@ input.onGesture(Gesture.Shake, function () {
36
36
 
37
37
  ## Send the dice
38
38
 
39
- Put in a ``||radio:send number||`` and a ``||dice||`` to send the value stored in the ``dice`` variable via radio.
39
+ Put in a ``||radio:send number||`` and a ``||variables:dice||`` to send the value stored in the ``||variables:dice||`` variable via radio. Make sure to add a ``||radio:set group||`` to ``||basic:on start||`` with the group number set to the group you want to use.
40
40
 
41
41
  ```blocks
42
+ radio.setGroup(1)
42
43
  let dice = 0
43
44
  input.onGesture(Gesture.Shake, function () {
44
45
  dice = randint(1, 6)
@@ -49,7 +50,7 @@ input.onGesture(Gesture.Shake, function () {
49
50
 
50
51
  ## Receive the dice
51
52
 
52
- Go get an ``||radio:on received number||`` event block. This event runs when a radio message from another @boardname@ arrives. The ``receivedNumber`` value is the value of the dice in this game.
53
+ Go get an ``||radio:on received number||`` event block. This event runs when a radio message from another @boardname@ arrives. The ``||variables:receivedNumber||`` value is the value of the dice in this game.
53
54
 
54
55
  ```blocks
55
56
  radio.onReceivedNumber(function (receivedNumber) {
@@ -58,7 +59,7 @@ radio.onReceivedNumber(function (receivedNumber) {
58
59
 
59
60
  ## Check your cast
60
61
 
61
- Add a ``||logic:if||`` block to test if ``receivedNumber`` is greater or equal to ``dice``.
62
+ Add a ``||logic:if||`` block to test if ``||variables:receivedNumber||`` is greater or equal to ``||variables:dice||``.
62
63
  If is, you lost so display a sad face on the screen.
63
64
 
64
65
  ```blocks
@@ -78,6 +79,7 @@ If you have more than one @boardname@, download your code onto each one and try
78
79
 
79
80
  ```blocks
80
81
  let dice = 0
82
+ radio.setGroup(1)
81
83
  input.onGesture(Gesture.Shake, function () {
82
84
  dice = randint(1, 6)
83
85
  basic.showNumber(dice)
@@ -6,7 +6,7 @@ The ``||led:plot bar graph||`` uses the screen to display the _magnitude_ (how b
6
6
 
7
7
  ## Acceleration
8
8
 
9
- In a ``||loops:forever||`` loop, ``||led:plot||`` ``||input:acceleration||`` in the ``x`` dimension on the LEDs.
9
+ In a ``||basic:forever||`` loop, ``||led:plot||`` ``||input:acceleration||`` in the ``x`` dimension on the LEDs.
10
10
 
11
11
  ```blocks
12
12
  basic.forever(function() {
@@ -50,4 +50,4 @@ basic.forever(function() {
50
50
 
51
51
  ## Download and try
52
52
 
53
- Download the code to your @boardname@ and test the sensors.
53
+ Download the code to your @boardname@ and test the sensors.
@@ -0,0 +1,317 @@
1
+ # Blow Away
2
+
3
+ ## 1. Introduction pt. 1 @unplugged
4
+
5
+ 👻 Oh, no! Your @boardname@ is being haunted by a ghost named Haven 👻
6
+
7
+ For this tutorial, we'll learn how to blow Haven away 🌬️
8
+
9
+ ![Blow away banner message](/static/mb/projects/blow-away.png)
10
+
11
+ ## 2. Haunted ghost setup
12
+
13
+ 🏚️ **BooOooOoo** 🏚️
14
+
15
+ A wild Haven has appeared!
16
+
17
+ ---
18
+
19
+ ► From the ``||basic:Basic||`` category, find ``||basic:show icon [ ]||`` and add it to your ``||basic:on start||`` container.
20
+
21
+ ► Click the heart icon and set it to show a ghost.
22
+ 💡 In the ``show icon`` dropdown menu options, you can hover to see what each design is called.
23
+
24
+ ```blocks
25
+ // @highlight
26
+ basic.showIcon(IconNames.Ghost)
27
+ ```
28
+
29
+ ---
30
+
31
+ ## 3. Loop setup
32
+
33
+ ➰ **Looping around** ➰
34
+
35
+ ---
36
+
37
+ ► From the ``||loops:Loops||`` category, find the ``||loops:repeat [4] times||`` loop and snap it into your empty ``||basic:forever||`` container.
38
+ 💡 Why do we need a [__*repeat loop*__](#repeatLoop "repeat code for a given number of times") when we already have a ``forever`` container? Because ``forever`` has an embedded delay that we want to avoid!
39
+
40
+ ```blocks
41
+ basic.forever(function () {
42
+ // @highlight
43
+ for (let index = 0; index < 4; index++) {
44
+
45
+ }
46
+ })
47
+ ```
48
+
49
+ ## 4. Conditional setup
50
+
51
+ 🤔 **Conditioning and comparing** 🤔
52
+
53
+ Haven hates noise and will blow away if things get too loud. Let's use an [__*if statement*__](#ifstatement "if this condition is met, do something") to check for sounds.
54
+
55
+ ---
56
+
57
+ ► From ``||logic:Logic||``, grab an ``||logic:if <true> then||`` statement and snap it into your empty ``||loops:repeat [4] times do||`` loop.
58
+
59
+ ► Go back to ``||logic:Logic||`` to get a ``||logic:<[0] [=] [0]>||`` comparison.
60
+
61
+ ► Snap ``||logic:<[0] [=] [0]>||`` in to **replace** the ``||logic:<true>||`` condition for your ``||logic:if then||`` statement.
62
+
63
+ ```blocks
64
+ basic.forever(function () {
65
+ // @highlight
66
+ for (let index = 0; index < 4; index++) {
67
+ // @highlight
68
+ if (0 == 0) {
69
+
70
+ }
71
+ }
72
+ })
73
+ ```
74
+
75
+ ## 5. Blow sound
76
+
77
+ 👂 **Haven's ears** 👂
78
+
79
+ We'll be using a [__*sound threshold*__](#soundThreshold "a number for how loud a sound needs to be to trigger an event. 0 = silence to 255 = maximum noise") to act as Haven's ears.
80
+
81
+ ---
82
+
83
+ ► From the ``||input:Input||`` category, drag ``||input:sound level||`` in to **replace** the **_left_ ``0``** of your ``||logic:<[0] [=] [0]>||`` comparison.
84
+
85
+ ► Using the dropdown in the **middle** of ``||logic:[sound level] [=] [0]||``, change the comparison to be **``>``** (greater than).
86
+
87
+ ► Finally, have the **right side** of the comparison say ``128`` so your full comparison reads: **``sound level > 128``**.
88
+ 💡 This means Haven will hear any sound above ``128``.
89
+
90
+ ```blocks
91
+ basic.forever(function () {
92
+ for (let index = 0; index < 4; index++) {
93
+ // @highlight
94
+ if (input.soundLevel() > 128) {
95
+
96
+ }
97
+ }
98
+ })
99
+ ```
100
+
101
+ ## 6. Making variables
102
+
103
+ ☀️ **Variable weather** 🌨️
104
+
105
+ Let's create some [__*variables*__](#variable "a holder for information that may change") to keep track of Haven's movement.
106
+
107
+ ---
108
+
109
+ ► In the ``||variables:Variables||`` category, click on ``Make a Variable...`` and make a variable named ``col``.
110
+ 💡 ``col`` is short for "column".
111
+
112
+ ► Make **another** variable and name it ``row``.
113
+
114
+ ## 7. Displacing LEDs part 1
115
+
116
+ 🔀 **Random chance** 🔀
117
+
118
+ To show Haven is blowing away, we want to move a random set of lights sideways.
119
+
120
+ ---
121
+
122
+ ► Your ``||variables:Variables||`` category should now have the option to ``||variables:set [row] to [0]||``. Drag that block into your empty ``||logic:if then||`` statement.
123
+
124
+ ► From the ``||math:Math||`` category, find ``||math:pick random [0] to [10]||`` and snap that in to **replace** the ``[0]`` in your ``||variables:set [row] to [0]||`` block.
125
+
126
+ ► Change the maximum number from ``10`` to **``4``**.
127
+ 💡 We are setting the maximum random value to 4 because the lights on the @boardname@ are numbered 0, 1, 2, 3, and 4 for columns and rows.
128
+
129
+ ```blocks
130
+ let row = 0
131
+ basic.forever(function () {
132
+ for (let index = 0; index < 4; index++) {
133
+ if (input.soundLevel() > 128) {
134
+ // @highlight
135
+ row = randint(0, 4)
136
+ }
137
+ }
138
+ })
139
+ ```
140
+
141
+ ## 8. Displacing LEDs part 2
142
+
143
+ ► Go back into ``||variables:Variables||`` and drag out another ``||variables:set [row] to [0]||``. Place this one below the last one (at **the end**) of your `if then` statement.
144
+
145
+ ► Using the **dropdown menu**, set the new block to read ``||variables:set [col] to [0]||``.
146
+
147
+ ► From the ``||math:Math||`` category, grab another ``||math:pick random [0] to [10]||`` and snap that in to **replace** the ``[0]`` in your ``||variables:set [col] to [0]||`` block.
148
+
149
+ ► Change the maximum number from ``10`` to **``4``**.
150
+
151
+ ```blocks
152
+ let col = 0
153
+ let row = 0
154
+ basic.forever(function () {
155
+ for (let index = 0; index < 4; index++) {
156
+ if (input.soundLevel() > 128) {
157
+ row = randint(0, 4)
158
+ // @highlight
159
+ col = randint(0, 4)
160
+ }
161
+ }
162
+ })
163
+ ```
164
+
165
+ ## 9. Conditioning on one point
166
+
167
+ ✨ **Ooh, sparkly** ✨
168
+
169
+ Time to move some lights around!
170
+
171
+ ---
172
+
173
+ ► From ``||logic:Logic||``, grab another ``||logic:if <true> then||`` and snap it at the **inside and at the bottom of** your ``||loops:repeat [4] times do||`` loop, right below your ``||logic:if [sound level] [>] [128]||`` statement.
174
+
175
+ ► From the ``||led:Led||`` category, find ``||led:point x [0] y [0]||`` and drag it in to **replace** the ``||logic:<true>||`` condition in the **new** ``||logic:if then||`` statement.
176
+ 💡 This block will test if the light is on at the the given ``x`` and ``y`` coordinate points.
177
+
178
+ ```blocks
179
+ let col = 0
180
+ let row = 0
181
+ basic.forever(function () {
182
+ for (let index = 0; index < 4; index++) {
183
+ if (input.soundLevel() > 128) {
184
+ row = randint(0, 4)
185
+ col = randint(0, 4)
186
+ }
187
+ // @highlight
188
+ if (led.point(0, 0)) { }
189
+ }
190
+ })
191
+ ```
192
+
193
+ ## 10. Unplotting and replotting LEDs
194
+
195
+ To create the animation effect of Haven blowing away, we will turn off (or ``unplot``) a light that is on and then turn it on again (``plot`` it) in a different spot.
196
+
197
+ ---
198
+
199
+ ► From ``||led:Led||``, grab ``||led:unplot x [0] y [0]||`` and snap it inside the **empty** ``||logic:if <point x [0] y [0]> then||`` statement.
200
+
201
+ ► Go back to ``||led:Led||`` and get ``||led:plot x [0] y [0]||``. Snap that in **beneath** the ``||led:unplot x [0] y [0]||`` block that you just added.
202
+
203
+ ```blocks
204
+ let col = 0
205
+ let row = 0
206
+ basic.forever(function () {
207
+ for (let index = 0; index < 4; index++) {
208
+ if (input.soundLevel() > 128) {
209
+ row = randint(0, 4)
210
+ col = randint(0, 4)
211
+ }
212
+ // @highlight
213
+ if (led.point(0, 0)) {
214
+ led.unplot(0, 0)
215
+ led.plot(0, 0)
216
+ }
217
+ }
218
+ })
219
+ ```
220
+
221
+ ## 11. Setting variables
222
+
223
+ 📃 **Columns and rows** 📃
224
+
225
+ Notice how you have **three** blocks from the ``||led:Led||`` category. All three have ``||led:x||`` ``[0]`` and ``||led:y||`` ``[0]`` coordinates. In these **two** steps, we will set it so that every ``||led:x||`` is followed by the ``||variables:col||`` variable and every ``||led:y||`` is followed by the ``||variables:row||`` variable.
226
+
227
+ ---
228
+
229
+ ► From ``||variables:Variables||``, get three copies of ``||variables:col||``, and use them to **replace the ``x`` values** in the following three blocks:
230
+ **1.** ``||led:point x [0] y [0]||``
231
+ **2.** ``||led:unplot x [0] y [0]||``
232
+ **3.** ``||led:plot x [0] y [0]||``
233
+
234
+ ► Go into ``||variables:Variables||``, get three copies of ``||variables:row||``, and use them to **replace the ``y`` values** in the same three blocks.
235
+
236
+ ```blocks
237
+ let col = 0
238
+ let row = 0
239
+ basic.forever(function () {
240
+ for (let index = 0; index < 4; index++) {
241
+ if (input.soundLevel() > 128) {
242
+ row = randint(0, 4)
243
+ col = randint(0, 4)
244
+ }
245
+ // @highlight
246
+ if (led.point(col, row)) {
247
+ led.unplot(col, row)
248
+ led.plot(col, row)
249
+ }
250
+ }
251
+ })
252
+ ```
253
+
254
+ ## 12. Moving LEDs
255
+
256
+ ➕ **Math makes the lights go swoosh** ➗
257
+
258
+ Right now, we are unplotting and replotting in the same spot. What we want to do is move the lights we're turning back on just a smidge to the right every time until there's nothing left on the grid.
259
+
260
+ ---
261
+
262
+ ► From ``||math:Math||``, find the ``||math:[0] [+] [0]||`` operation and use it to **replace** ``||variables:col||`` in your ``||led:plot x [col] y [row]||`` block.
263
+ 💡 If you move your entire ``||basic:forever||`` container, you should find a greyed out ``col`` variable in your workspace.
264
+
265
+ ► Take the greyed out ``||variables:col||`` variable (or get a new one) and use it to **replace** the **_first_ ``[0]``** so the operation reads ``||math:[col] [+] [0]||``.
266
+
267
+ ► Replace the **_second_ ``[0]``** with **``[1]``** so the operation reads ``||math:[col] [+] [1]||``.
268
+
269
+ ```blocks
270
+ let col = 0
271
+ let row = 0
272
+ basic.forever(function () {
273
+ for (let index = 0; index < 4; index++) {
274
+ if (input.soundLevel() > 128) {
275
+ row = randint(0, 4)
276
+ col = randint(0, 4)
277
+ }
278
+ // @highlight
279
+ if (led.point(col, row)) {
280
+ led.unplot(col, row)
281
+ led.plot(col + 1, row)
282
+ }
283
+ }
284
+ })
285
+ ```
286
+
287
+ ## 13. Testing in the simulator
288
+
289
+ 🌬️ **Test what you've created** 👻
290
+
291
+ Check out the simulator!
292
+
293
+ ---
294
+
295
+ ► Click on the pink bar underneath the microphone icon. Drag it above the sound number you chose (we used ``128``!) to blow Haven away.
296
+
297
+ ► If you have a new @boardname@ (the one with the **shiny gold** logo at the top), download this code and try it out!
298
+ 💡 Blow close to the @boardname@ and watch Haven swoosh away 💨
299
+ 💡 Use your @boardname@'s reset button (it's on the back!) to bring Haven back 👻
300
+
301
+ ```blocks
302
+ let col = 0
303
+ let row = 0
304
+ basic.showIcon(IconNames.Ghost)
305
+ basic.forever(function () {
306
+ for (let index = 0; index < 4; index++) {
307
+ if (input.soundLevel() > 128) {
308
+ row = randint(0, 4)
309
+ col = randint(0, 4)
310
+ }
311
+ if (led.point(col, row)) {
312
+ led.unplot(col, row)
313
+ led.plot(col + 1, row)
314
+ }
315
+ }
316
+ })
317
+ ```