pxt-microbit 5.0.12 → 5.1.2

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 (42) hide show
  1. package/built/editor.js +36 -2
  2. package/built/target-strings.json +5 -0
  3. package/built/target.js +46 -36
  4. package/built/target.json +46 -36
  5. package/built/targetlight.json +5 -5
  6. package/built/theme.json +11 -0
  7. package/built/web/react-common-authcode.css +6 -2
  8. package/built/web/react-common-skillmap.css +1 -1
  9. package/built/web/rtlreact-common-skillmap.css +1 -1
  10. package/built/web/rtlsemantic.css +1 -1
  11. package/built/web/semantic.css +1 -1
  12. package/docs/SUMMARY.md +2 -0
  13. package/docs/device/pins.md +72 -40
  14. package/docs/extensions.md +8 -0
  15. package/docs/jacdac.md +60 -0
  16. package/docs/projects/SUMMARY.md +10 -0
  17. package/docs/projects/games.md +6 -0
  18. package/docs/projects/magic-button-trick.md +0 -2
  19. package/docs/projects/rock-paper-scissors-v2.md +201 -0
  20. package/docs/projects/v2-cat-napping.md +219 -0
  21. package/docs/projects.md +6 -0
  22. package/docs/reference/input/logo-is-pressed.md +1 -1
  23. package/docs/reference/input/on-logo-event.md +1 -1
  24. package/docs/reference/serial/on-data-received.md +1 -1
  25. package/docs/reference/serial/read-buffer.md +8 -7
  26. package/docs/reference/serial/read-line.md +8 -6
  27. package/docs/reference/serial/read-string.md +4 -4
  28. package/docs/reference/serial/read-until.md +4 -4
  29. package/docs/reference/serial/redirect.md +8 -7
  30. package/docs/reference/serial/set-baud-rate.md +56 -0
  31. package/docs/reference/serial/set-write-line-padding.md +51 -0
  32. package/docs/reference/serial/write-buffer.md +4 -4
  33. package/docs/reference/serial/write-line.md +6 -6
  34. package/docs/reference/serial/write-number.md +6 -6
  35. package/docs/reference/serial/write-numbers.md +6 -6
  36. package/docs/reference/serial/write-string.md +5 -5
  37. package/docs/reference/serial/write-value.md +3 -3
  38. package/docs/reference/serial.md +4 -1
  39. package/docs/tutorials-v2.md +6 -0
  40. package/package.json +2 -2
  41. package/pxtarget.json +1 -0
  42. package/targetconfig.json +9 -4
package/docs/SUMMARY.md CHANGED
@@ -295,6 +295,8 @@
295
295
  * [on data received](/reference/serial/on-data-received)
296
296
  * [redirect](/reference/serial/redirect)
297
297
  * [redirect to usb](/reference/serial/redirect-to-usb)
298
+ * [set baud rate](/reference/serial/set-baud-rate)
299
+ * [set write line padding](/reference/serial/set-write-line-padding)
298
300
  * [write buffer](/reference/serial/write-buffer)
299
301
  * [read buffer](/reference/serial/read-buffer)
300
302
  * [Control](/reference/control)
@@ -1,64 +1,96 @@
1
1
  # micro:bit pins
2
2
 
3
- The micro:bit pins
3
+ The micro:bit has **25** external connections on the edge connector of the board, which are referred to as 'pins'. The edge connector is the gold area on the right side of board as shown the figure below.
4
4
 
5
- ![](/static/mb/device/pins-0.png)
5
+ ![micro:bit v1 pins](/static/mb/device/pins-v1-v2.png)
6
6
 
7
- The micro:bit has 25 external connections on the edge connector of the board, which we refer to as ‘pins’. The edge connector is the grey area on the right side of the figure above.
8
-
9
- There are five large pins, that are also connected to holes in the board labelled: 0, 1, 2, 3V, and GND. And along the same edge, there are 20 small pins that you can use when plugging the micro:bit into an edge connector.
7
+ There are **5 large pins** that are also connected to holes in the board labelled: **0**, **1**, **2**, **3V**, and **GND**. And along the same edge, there are **20 small pins** that you can use when plugging the micro:bit into an edge connector.
10
8
 
11
9
  ## Large pins
12
10
 
13
- You can easily attach crocodile clips or 4mm banana plugs to the five large pins.
11
+ You can easily attach crocodile clips or 4mm banana plugs to the **5** large pins.
14
12
 
15
- The first three, labelled 0, 1 and 2 are flexible and can be used for many different things - which means they are often called general purpose input and output (shortened to GPIO). These three pins also have the ability to read analogue voltages using something called an analogue-to-digital converter (ADC). They all have the same function:
13
+ The first three, labelled **0**, **1** and **2** are flexible and can be used for many different things - which means they are often called "general purpose input and output" (shortened to GPIO). These three pins also have the ability to read analog voltages using something called an analog-to-digital converter (ADC). They all have the same function:
16
14
 
17
- * **0**: GPIO (general purpose digital input and output) with analogue to digital convertor (ADC).
15
+ * **0**: GPIO (general purpose digital input and output) with analog-to-digital convertor (ADC).
18
16
  * **1**: GPIO with ADC
19
17
  * **2**: GPIO with ADC
20
18
 
21
- The other two large pins (3V and GND) are very different!
19
+ With the micro:bit V2, pins **0**, **1**, **2**, and the **LOGO** can also be set to work as [capacitive touch](/reference/pins/touch-set-mode) buttons.
20
+
21
+ ### Power pins
22
+
23
+ The other two large pins (**3V** and **GND**) are very different!
22
24
 
23
- ## ~hint
25
+ ### ~hint
24
26
 
25
- Watch out! The pins labelled 3V and GND relate to the power supply of the board, and they should NEVER be connected together.
26
- For details on the power, current and voltage limitations of the board, see [Power Supply](https://tech.microbit.org/hardware/powersupply/)
27
+ #### Be careful with the power pins
27
28
 
28
- ## ~
29
+ Watch out! The pins labelled **3V** and **GND** relate to the power supply of the board, and they should NEVER be connected together.
29
30
 
30
- *power input*: If the micro:bit is powered by USB or a battery, then you can use the 3V pin as a *power output* to power peripherals with.
31
+ For details on the power, current and voltage limitations of the board, see [Power Supply](https://tech.microbit.org/hardware/powersupply/).
31
32
 
32
- * **3V**: *3 volt power output* or *power input*. (1) *power output*: If the micro:bit is powered by USB or a battery, then you can use the 3V pin as a power output to power peripherals with; (2) *power input*: If the micro:bit is not being powered by USB or battery, you can use the 3V pin as a power input to power the micro:bit
33
- * **GND**: attaches to ground in order to complete a circuit (required when using the 3V pin)
33
+ ### ~
34
34
 
35
- If you hold the ‘GND’ pin with one hand, you can program the microbit to detect yourself touching the 0,1 or 2 pins with your other hand, giving you three more buttons to experiment with (you just used your body to complete an electrical circuit).
35
+
36
+ * **3V**: 3 volt *power output* or *power input*:
37
+ >* *power output*: If the micro:bit is powered by USB or a battery, then you can use the **3V** pin as a power output to power peripherals with.
38
+ >* *power input*: If the micro:bit is NOT being powered by USB or battery, you can use the **3V** pin to supply power input to the micro:bit.
39
+ * **GND**: attaches to ground in order to complete a circuit (required when using the **3V** pin)
40
+
41
+ If you hold the **GND** pin with one hand, you can program the microbit to detect yourself touching the **0**, **1** or **2** pins with your other hand, giving you three more buttons to experiment with (you just used your body to complete an electrical circuit to make "resistive touch" buttons).
36
42
 
37
43
  ## Small pins
38
44
 
39
- There are 20 small pins numbered sequentially from 3-22 (these pins are not labeled on the micro:bit, however, they are labelled in the picture above).
40
-
41
- Unlike the three large pins that are dedicated to being used for external connections, some of the small pins are shared with other components on the micro:bit board. For example, pin 3 is shared with some of the LEDs on the screen of the micro:bit, so if you are using the screen to scroll messages, you can’t use this pin as well.
42
-
43
- * **pin 3**: GPIO shared with LED Col 1 of the LED screen; can be used for ADC and digital I/O when the LED screen is turned off.
44
- * **pin 4**: GPIO shared with LED Col 2 of the LED screen; can be used for ADC and digital I/O when the LED screen is turned off.
45
- * **pin 5**: GPIO shared with Button A. This lets you trigger or detect a button "A" click externally. This pin has a pull-up resistor, which means that by default it is at voltage of 3V. To replace button A on the micro:bit with an external button, connect one end of the external button to pin 5 and the other end to GND. When the button is pressed, the voltage on pin 5 is pulled down to 0, which generates a button click event.
46
- * **pin 6**: GPIO shared with LED Col 9 of the LED screen; can be used for digital I/O when the LED screen is turned off.
47
- * **pin 7**: GPIO shared with LED Col 8 of the LED screen; can be used for digital I/O when the LED screen is turned off.
48
- * **pin 8**: Dedicated GPIO, for sending and sensing digital signals.
49
- * **pin 9**: GPIO shared with LED Col 7 of the LED screen; can be used for digital I/O when the LED screen is turned off.
50
- * **pin 10**: GPIO shared with LED Col 3 of the LED screen; can be used for ADC and digital I/O when the LED screen is turned off.
51
- * **pin 11**: GPIO shared with Button B. This lets you trigger or detect a button “B” click externally.
52
- * **pin 12**: this GPIO pin has been reserved to provide support for accessibility.
53
- * **pin 13**: GPIO that is conventionally used for the serial clock (SCK) signal of the 3-wire Serial Peripheral Interface (SPI) bus.
54
- * **pin 14**: GPIO that is conventionally used for the Master In Slave Out (MISO) signal of the SPI bus.
55
- * **pin 15**: GPIO that is conventionally used for the Master Out Slave In (MOSI) signal of the SPI bus.
56
- * **pin 16**: Dedicated GPIO (conventionally also used for SPI ‘Chip Select’ function).
57
- * **pins 17 and 18**: these pins are wired to the 3V supply, like the large ‘3V’ pad.
58
- * **pins 19 and 20**: implement the clock signal (SCL) and data line (SDA) of the I2C bus communication protocol. With I2C, several devices can be connected on the same bus and send/read messages to and from the CPU. Internally, the accelerometer and the compass are connected to i2c.
59
- * **pins 21 and 22**: these pins are wired to the GND pin and serve no other function
45
+ The **20** small pins are numbered sequentially from **3-22** (these pins are not labeled on the micro:bit, however, they are labelled in the picture above).
46
+
47
+ Unlike the three large pins that are dedicated to being used for external connections, some of the small pins are shared with other components on the micro:bit board. For example, pin **3** is shared with some of the LEDs on the screen of the micro:bit, so if you are using the screen to scroll messages, you can’t use this pin as well.
48
+
49
+ There are some differences in function assignments for the small pins between the micro:bit versions. The following pin tables describe the pin functions for each version.
50
+
51
+ ### V1 pin map
52
+
53
+ | Pin | Description |
54
+ | - | - |
55
+ | **3** | GPIO shared with LED Col 1 of the LED screen; can be used for ADC and digital I/O when the LED screen is turned off. |
56
+ | **4** | GPIO shared with LED Col 2 of the LED screen; can be used for ADC and digital I/O when the LED screen is turned off. |
57
+ | **5** | GPIO shared with Button A. This lets you trigger or detect a button "A" click externally. This pin has a pull-up resistor, which means that by default it is at voltage of 3V. To replace button A on the micro:bit with an external button, connect one end of the external button to pin 5 and the other end to GND. When the button is pressed, the voltage on pin 5 is pulled down to 0, which generates a button click event. |
58
+ | **6** | GPIO shared with LED Col 9 of the LED screen; can be used for digital I/O when the LED screen is turned off. |
59
+ | **7** | GPIO shared with LED Col 8 of the LED screen; can be used for digital I/O when the LED screen is turned off. |
60
+ | **8** | Dedicated GPIO, for sending and sensing digital signals.
61
+ | **9** | GPIO shared with LED Col 7 of the LED screen; can be used for digital I/O when the LED screen is turned off. |
62
+ | **10** | GPIO shared with LED Col 3 of the LED screen; can be used for ADC and digital I/O when the LED screen is turned off.|
63
+ | **11** | GPIO shared with Button B. This lets you trigger or detect a button "B" click externally. |
64
+ | **12** | This GPIO pin has been reserved to provide support for accessibility. |
65
+ | **13** | GPIO that is conventionally used for the serial clock (SCK) signal of the 3-wire Serial Peripheral Interface (SPI) bus. |
66
+ | **14** | GPIO that is conventionally used for the Master In Slave Out (MISO) signal of the SPI bus. |
67
+ | **15** | GPIO that is conventionally used for the Master Out Slave In (MOSI) signal of the SPI bus. |
68
+ | **16** | Dedicated GPIO (conventionally also used for SPI 'Chip Select' function). |
69
+ | **17, 18** | These pins are wired to the 3V supply, like the large '3V' pad. |
70
+ | **19, 20** | Implement the clock signal (SCL) and data line (SDA) of the I2C bus communication protocol. With I2C, several devices can be connected on the same bus and send/read messages to and from the CPU. Internally, the accelerometer and the compass are connected to i2c. |
71
+ | **21, 22** | These pins are wired to the GND pin and serve no other function. |
72
+
73
+ ### V2 pin map
74
+
75
+ | Pin | Description |
76
+ | - | - |
77
+ | **3** | GPIO shared with LED Col 3 of the LED screen; can be used for ADC and digital I/O when the LED screen is turned off. |
78
+ | **4** | GPIO shared with LED Col 1 of the LED screen; can be used for ADC and digital I/O when the LED screen is turned off. |
79
+ | **5** | GPIO shared with Button A. This lets you trigger or detect a button "A" click externally. This pin has a pull-up resistor, which means that by default it is at voltage of 3V. To replace button A on the micro:bit with an external button, connect one end of the external button to pin 5 and the other end to GND. When the button is pressed, the voltage on pin 5 is pulled down to 0, which generates a button click event. |
80
+ | **6** | GPIO shared with LED Col 2 of the LED screen; can be used for digital I/O when the LED screen is turned off. |
81
+ | **7** | GPIO shared with LED Col 4 of the LED screen; can be used for digital I/O when the LED screen is turned off. |
82
+ | **8, 9** | Dedicated GPIO, for sending and sensing digital signals; can also be configured for NFC. |
83
+ | **10** | GPIO shared with LED Col 5 of the LED screen; can be used for ADC and digital I/O when the LED screen is turned off.|
84
+ | **11** | GPIO shared with Button B. This lets you trigger or detect a button "B" click externally. |
85
+ | **12** | This GPIO pin has been reserved to provide support for accessibility. |
86
+ | **13** | GPIO that is conventionally used for the serial clock (SCK) signal of the 3-wire Serial Peripheral Interface (SPI) bus. |
87
+ | **14** | GPIO that is conventionally used for the Master In Slave Out (MISO) signal of the SPI bus. |
88
+ | **15** | GPIO that is conventionally used for the Master Out Slave In (MOSI) signal of the SPI bus. |
89
+ | **16** | Dedicated GPIO (conventionally also used for SPI 'Chip Select' function). |
90
+ | **17, 18** | These pins are wired to the 3V supply, like the large '3V' pad. |
91
+ | **19, 20** | Implement the clock signal (SCL) and data line (SDA) of the I2C bus communication protocol. With I2C, several devices can be connected on the same bus and send/read messages to and from the CPU. Internally, the accelerometer and the compass are connected to i2c. |
92
+ | **21, 22** | These pins are wired to the GND pin and serve no other function. |
60
93
 
61
94
  ## Connecting to the small pins
62
95
 
63
- It is recommended that an edge connector be acquired to connect to the small pins. More information on compatible edge connectors will be available later.
64
-
96
+ It is recommended that an edge connector designed for the micro:bit be used for connections to the small pins. For available edge connectors, put "edge eonnectors for the micro:bit" into your internet search engine to find an accessory supplier.
@@ -310,6 +310,10 @@ Check out [the accessories pages on microbit.org](https://microbit.org/buy/acces
310
310
 
311
311
  ```codecard
312
312
  [{
313
+ "name": "DFRobot IoT Cloud Kit",
314
+ "url":"/pkg/DFRobot/pxt-DFRobot_IoT_Cloud_Kit",
315
+ "cardType": "package"
316
+ }, {
313
317
  "name": "iClass IoT",
314
318
  "url":"/pkg/KelieLeung/pxt-iClassIoT",
315
319
  "cardType": "package"
@@ -632,6 +636,10 @@ Check out [the accessories pages on microbit.org](https://microbit.org/buy/acces
632
636
  "name": "ReroKit rero:micro",
633
637
  "url":"/pkg/ReRoKit/pxt-reromicro",
634
638
  "cardType": "package"
639
+ }, {
640
+ "name": "PLEN bit full",
641
+ "url":"/pkg/plenprojectcompany/pxt-PLENbit_full",
642
+ "cardType": "package"
635
643
  }, {
636
644
  "name": "PLEN bit",
637
645
  "url":"/pkg/plenprojectcompany/pxt-PLENbit",
package/docs/jacdac.md ADDED
@@ -0,0 +1,60 @@
1
+ # Jacdac
2
+
3
+ Connect and Code. Instantly.
4
+
5
+ ## Getting started
6
+
7
+ [Jacdac](https://aka.ms/jacdac) is a plug-and-play hardware accessory system that provides simulation and physical device twin in MakeCode.
8
+
9
+ ```codecard
10
+ [{
11
+ "name": "Getting started",
12
+ "description": "Connect and Code. Instantly in MakeCode.",
13
+ "url":"https://microsoft.github.io/jacdac-docs/clients/makecode/",
14
+ "imageUrl": "/static/jacdac/getting-started.jpg"
15
+ }]
16
+ ```
17
+
18
+ ## Projects
19
+
20
+ ```codecard
21
+ [
22
+ {
23
+ "name": "Button smasher",
24
+ "description": "How many times can you smash the button in 10 seconds?",
25
+ "url": "https://microsoft.github.io/jacdac-docs/clients/makecode/projects/button-smasher/",
26
+ "imageUrl": "/static/jacdac/button-smasher.jpg",
27
+ "youTubeId": "rlK_8oqMAmo"
28
+ },
29
+ {
30
+ "name": "Slider Sound Bender",
31
+ "description": "Create twisted sounds using a slider module.",
32
+ "url": "https://microsoft.github.io/jacdac-docs/clients/makecode/projects/slider-sound-bender/",
33
+ "imageUrl": "/static/jacdac/slider-sound-bender.jpg"
34
+ },
35
+ {
36
+ "name": "Light Sound Bender",
37
+ "description": "Create twisted sounds using light levels",
38
+ "url": "https://microsoft.github.io/jacdac-docs/clients/makecode/projects/light-sound-bender/",
39
+ "imageUrl": "/static/jacdac/light-sound-bender.jpg"
40
+ },
41
+ {
42
+ "name": "Rotary Sound Bender",
43
+ "description": "Create twisted sounds using a rotary encoder module.",
44
+ "url": "https://microsoft.github.io/jacdac-docs/clients/makecode/projects/rotary-sound-bender/",
45
+ "imageUrl": "/static/jacdac/rotary-sound-bender.jpg"
46
+ },
47
+ {
48
+ "name": "Sound LED",
49
+ "description": "Show the sound level on a LED ring",
50
+ "url": "https://microsoft.github.io/jacdac-docs/clients/makecode/projects/sound-led/",
51
+ "imageUrl": "/static/jacdac/sound-led.jpg"
52
+ },
53
+ {
54
+ "name": "Magnetic Sound Bender",
55
+ "description": "Create twisted sounds using a magnet",
56
+ "url": "https://microsoft.github.io/jacdac-docs/clients/makecode/projects/magnetic-sound-bender/",
57
+ "imageUrl": "/static/jacdac/magnetic-sound-bender.jpg"
58
+ }
59
+ ]
60
+ ```
@@ -13,6 +13,7 @@
13
13
  * [Morse Chat](/projects/v2-morse-chat)
14
14
  * [Clap Lights](/projects/v2-clap-lights)
15
15
  * [Blow Away](/projects/v2-blow-away)
16
+ * [Cat Napping](/projects/v2-cat-napping)
16
17
  * [Live Coding](/live-coding)
17
18
  * [Flashing Heart](https://youtu.be/NvEOKZ8wh9s)
18
19
  * [Name Tag](https://youtu.be/xpRI5jjQ31E)
@@ -49,6 +50,7 @@
49
50
  * [PlayList](https://www.youtube.com/playlist?list=PLMMBk9hE-SepocOwueEtTDyOPI_TBE9yC)
50
51
  * [Games](/projects/games)
51
52
  * [Rock Paper Scissors](/projects/rock-paper-scissors)
53
+ * [Rock Paper Scissors V2](/projects/rock-paper-scissors-v2)
52
54
  * [Coin Flipper](/projects/coin-flipper)
53
55
  * [7 seconds](/projects/7-seconds)
54
56
  * [Hot Potato](/projects/hot-potato)
@@ -138,6 +140,14 @@
138
140
  * [Kitronik Inventor Kit](https://www.kitronik.co.uk/blog/inventors-kit-experiment-1-help)
139
141
  * [micro:bit of Things](https://sites.google.com/view/microbitofthings)
140
142
  * [A-Z Robotics](https://tinkerspark.teachable.com/)
143
+ * [Jacdac](/jacdac)
144
+ * [Getting started](https://microsoft.github.io/jacdac-docs/clients/makecode/)
145
+ * [Button smasher](https://microsoft.github.io/jacdac-docs/clients/makecode/projects/button-smasher/)
146
+ * [Slider Sound Bender](https://microsoft.github.io/jacdac-docs/clients/makecode/projects/slider-sound-bender/)
147
+ * [Light Sound Bender](https://microsoft.github.io/jacdac-docs/clients/makecode/projects/light-sound-bender/)
148
+ * [Rotary Sound Bender](https://microsoft.github.io/jacdac-docs/clients/makecode/projects/rotary-sound-bender/)
149
+ * [Sound LED](https://microsoft.github.io/jacdac-docs/clients/makecode/projects/sound-led/)
150
+ * [Magnetic Sound Bender](https://microsoft.github.io/jacdac-docs/clients/makecode/projects/magnetic-sound-bender/)
141
151
  * [Behind the MakeCode Hardware](/behind-the-makecode-hardware)
142
152
  * [LEDs](https://youtu.be/qqBmvHD5bCw)
143
153
  * [Buttons](https://youtu.be/t_Qujjd_38o)
@@ -24,6 +24,12 @@ Fun games to build with your @boardname@.
24
24
  "cardType": "tutorial"
25
25
  }]
26
26
  }, {
27
+ "name": "Rock Paper Scissors V2",
28
+ "url":"/projects/rock-paper-scissors-v2",
29
+ "description": "Rock Paper Scissors with Sounds for micro:bit V2!",
30
+ "imageUrl":"/static/mb/projects/a4-motion-v2.png",
31
+ "cardType": "tutorial"
32
+ },{
27
33
  "name": "Coin Flipper",
28
34
  "url":"/projects/coin-flipper",
29
35
  "description": "Guess the coin toss and see if you're lucky.",
@@ -8,8 +8,6 @@ Build a magic trick that uses the @boardname@'s compass to detect a nearby magne
8
8
 
9
9
  This is a simple magic trick you can perform to amaze your friends! When you move the sticky labels on your @boardname@'s **A** and **B** button, you appear to make the buttons really switch over. To see the trick performed watch the video below.
10
10
 
11
- https://youtu.be/-9KvmPopov8
12
-
13
11
  ## How the trick works
14
12
 
15
13
  The **magic** here is really in the code. This trick uses a magnet, hidden in your hand, to tell the @boardname@ to swap over the buttons. When the magnet is near the @boardname@, the **A** button starts working like the **B** button and the **B** button starts working like the **A** button. Tricky!
@@ -0,0 +1,201 @@
1
+ # Rock Paper Scissors V2
2
+
3
+ ## Introduction @unplugged
4
+
5
+ ![Cartoon of the Rock Paper Scissors game](/static/mb/projects/a4-motion-v2.png)
6
+
7
+ Build a "Rock Paper Scissors" game with ADDED BONUS SOUNDS using the **micro:bit V2** buzzer!
8
+
9
+ ## Step 1 @fullscreen
10
+
11
+ Add an ``||input:on shake||`` block to run code when you shake the @boardname@.
12
+
13
+ ```blocks
14
+ input.onGesture(Gesture.Shake, function () {
15
+
16
+ })
17
+ ```
18
+
19
+ ## Step 2 @fullscreen
20
+
21
+ Make a new variable called ``hand`` and place the ``||variables:set hand to||`` block in the shake event.
22
+
23
+ ![A animation that shows how to create a variable](/static/mb/projects/rock-paper-scissors/newvar.gif)
24
+
25
+ ## Step 3 @fullscreen
26
+
27
+ Add a ``||math:pick random||`` block to pick a random number from `1` to `3` and store it in the variable named ``hand``.
28
+
29
+ ```blocks
30
+ let hand = 0;
31
+ input.onGesture(Gesture.Shake, function () {
32
+ hand = randint(1, 3)
33
+ })
34
+ ```
35
+
36
+ In a later step, each of the possible numbers (`1`, `2`, or `3`) is matched to its own picture. The picture is shown on the LEDs when its matching number is picked.
37
+
38
+ ## Step 4 @fullscreen
39
+
40
+ Place an ``||logic:if||`` block under the ``||math:pick random||`` and check whether ``hand`` is equal to ``1``. Add a ``||basic:show leds||`` block that shows a picture of a piece of paper. The number `1` is the value for paper.
41
+
42
+ ![How to drag an if statement](/static/mb/projects/rock-paper-scissors/if.gif)
43
+
44
+ ```blocks
45
+ let hand = 0;
46
+ input.onGesture(Gesture.Shake, function () {
47
+ hand = randint(1, 3)
48
+ if (hand == 1) {
49
+ basic.showLeds(`
50
+ # # # # #
51
+ # . . . #
52
+ # . . . #
53
+ # . . . #
54
+ # # # # #
55
+ `)
56
+ }
57
+ })
58
+ ```
59
+
60
+ ## Step 5 @fullscreen
61
+
62
+ Place a ``||music:play sound||`` block under ``||basic:show leds||`` and edit it to make it sound like paper.
63
+
64
+ ```blocks
65
+ let hand = 0;
66
+ input.onGesture(Gesture.Shake, function () {
67
+ hand = randint(1, 3)
68
+ if (hand == 1) {
69
+ basic.showLeds(`
70
+ # # # # #
71
+ # . . . #
72
+ # . . . #
73
+ # . . . #
74
+ # # # # #
75
+ `)
76
+ music.playSoundEffect(music.createSoundEffect(WaveShape.Noise, 4120, 1266, 255, 148, 500, SoundExpressionEffect.Warble, InterpolationCurve.Curve), SoundExpressionPlayMode.UntilDone)
77
+ }
78
+ })
79
+ ```
80
+
81
+ ## Step 6 @fullscreen
82
+
83
+ Click on the **SHAKE** button in the simulator. If you try enough times, you should see a picture of paper on the screen.
84
+
85
+ ![Shaking a @boardname@ simulator](/static/mb/projects/rock-paper-scissors/rpsshake.gif)
86
+
87
+
88
+ ## Step 7 @fullscreen
89
+
90
+ Click the **(+)** button to add an ``||logic:else||`` section.
91
+
92
+ ![Adding an else clause](/static/mb/projects/rock-paper-scissors/ifelse.gif)
93
+
94
+ ```blocks
95
+ let hand = 0;
96
+ input.onGesture(Gesture.Shake, function () {
97
+ hand = randint(1, 3)
98
+ if (hand == 1) {
99
+ basic.showLeds(`
100
+ # # # # #
101
+ # . . . #
102
+ # . . . #
103
+ # . . . #
104
+ # # # # #
105
+ `)
106
+ music.playSoundEffect(music.createSoundEffect(WaveShape.Noise, 4120, 1266, 255, 148, 500, SoundExpressionEffect.Warble, InterpolationCurve.Curve), SoundExpressionPlayMode.UntilDone)
107
+ } else {
108
+
109
+ }
110
+ })
111
+ ```
112
+
113
+ ## Step 8 @fullscreen
114
+
115
+ Add both a ``||basic:show leds||`` block and a ``||music:play sound||`` block inside the ``||logic:else||``. Make a picture for **scissors** using LEDs and create a scissors sound.
116
+
117
+ ```blocks
118
+ let hand = 0;
119
+ input.onGesture(Gesture.Shake, function () {
120
+ hand = randint(1, 3)
121
+ if (hand == 1) {
122
+ basic.showLeds(`
123
+ # # # # #
124
+ # . . . #
125
+ # . . . #
126
+ # . . . #
127
+ # # # # #
128
+ `)
129
+ music.playSoundEffect(music.createSoundEffect(WaveShape.Noise, 4120, 1266, 255, 148, 500, SoundExpressionEffect.Warble, InterpolationCurve.Curve), SoundExpressionPlayMode.UntilDone)
130
+ } else {
131
+ basic.showLeds(`
132
+ # # . . #
133
+ # # . # .
134
+ . . # . .
135
+ # # . # .
136
+ # # . . #
137
+ `)
138
+ music.playSoundEffect(music.createSoundEffect(WaveShape.Sine, 4417, 1, 0, 255, 266, SoundExpressionEffect.Vibrato, InterpolationCurve.Linear), SoundExpressionPlayMode.UntilDone)
139
+ }
140
+ })
141
+ ```
142
+
143
+ ## Step 9 @fullscreen
144
+
145
+ Click the **(+)** button again to add an ``||logic:else if||`` section. Now, add a conditional block for ``||logic:hand = 2||`` to the empty slot in the ``||logic:else if||``. Since ``hand`` can only be `1`, `2`, or `3`, your code is now covering all possible cases!
146
+
147
+ ![Adding an else if clause](/static/mb/projects/rock-paper-scissors/ifelseif.gif)
148
+
149
+ ## Step 10 @fullscreen
150
+
151
+ Get one more ``||basic:show leds||`` block and ``||music:play sound||`` block and put them inside the ``||logic:else if||``. Make a picture of a rock in the LEDs and create a rock-like sound.
152
+
153
+ ```blocks
154
+ let hand = 0
155
+ input.onGesture(Gesture.Shake, function () {
156
+ hand = randint(1, 3)
157
+ if (hand == 1) {
158
+ basic.showLeds(`
159
+ # # # # #
160
+ # . . . #
161
+ # . . . #
162
+ # . . . #
163
+ # # # # #
164
+ `)
165
+ music.playSoundEffect(music.createSoundEffect(WaveShape.Noise, 4120, 1266, 255, 148, 500, SoundExpressionEffect.Warble, InterpolationCurve.Curve), SoundExpressionPlayMode.UntilDone)
166
+ } else if (hand == 2) {
167
+ basic.showLeds(`
168
+ . . . . .
169
+ . # # # .
170
+ . # # # .
171
+ . # # # .
172
+ . . . . .
173
+ `)
174
+ music.playSoundEffect(music.createSoundEffect(WaveShape.Sine, 4417, 1, 0, 255, 266, SoundExpressionEffect.Vibrato, InterpolationCurve.Linear), SoundExpressionPlayMode.UntilDone)
175
+ } else {
176
+ basic.showLeds(`
177
+ # # . . #
178
+ # # . # .
179
+ . . # . .
180
+ # # . # .
181
+ # # . . #
182
+ `)
183
+ music.playSoundEffect(music.createSoundEffect(WaveShape.Triangle, 1177, 4967, 0, 206, 266, SoundExpressionEffect.Tremolo, InterpolationCurve.Linear), SoundExpressionPlayMode.UntilDone)
184
+ }
185
+ })
186
+ ```
187
+
188
+ ## Step 11 @fullscreen
189
+
190
+ Click on the **SHAKE** button in the simulator and check to see that each image is showing up.
191
+
192
+ ![Shaking a @boardname@ simulator](/static/mb/projects/rock-paper-scissors/rpssim3.gif)
193
+
194
+ ## Step 12 @fullscreen
195
+
196
+ If you have a @boardname@ V2, click on ``|Download|`` and follow the instructions to get the code
197
+ onto your @boardname@.
198
+
199
+ Your game is ready! Gather your friends and play Rock Paper Scissors!
200
+
201
+ ![A @boardname@ in a hand](/static/mb/projects/rock-paper-scissors/hand.jpg)