Compare commits
225 Commits
Author | SHA1 | Date | |
---|---|---|---|
72226cd4e5 | |||
0d3af60892 | |||
f88cda8244 | |||
f71925fdd2 | |||
bfeda371a9 | |||
eb09530391 | |||
346d1e77da | |||
bf384355c4 | |||
3801e52370 | |||
99574f1ec8 | |||
12705eed06 | |||
a62f2b00b4 | |||
7d0101af25 | |||
60c3f1f427 | |||
8552a2de52 | |||
b0d4fdb009 | |||
d3294ee99e | |||
00d23f8437 | |||
1c6c749dad | |||
2803c00814 | |||
f150d93070 | |||
7f284b2a57 | |||
0e5c30ec7c | |||
2cc6f864a8 | |||
d428a2cd1f | |||
47f9362e5f | |||
38b197bc03 | |||
9a404854e7 | |||
d17a8de72d | |||
9d1f2e024b | |||
e7d8559fe3 | |||
fcfdbcc7e4 | |||
5884231399 | |||
e8887f5904 | |||
07e8610e5d | |||
37fb907f04 | |||
13f42f5892 | |||
5fcf9165ea | |||
b33d0ba470 | |||
b9f66c5c6b | |||
9848409283 | |||
ce16e64660 | |||
4d056e0c23 | |||
70b2827cf0 | |||
62e4b04931 | |||
17e33cc34f | |||
d4ad150cba | |||
52bfd4e535 | |||
f854dfd9c8 | |||
d905f24f9c | |||
81b8b1b69c | |||
efce4c3698 | |||
b5e4a36e9c | |||
04a60a5b47 | |||
29b28e7f0d | |||
979381eaef | |||
e4370f4e3c | |||
ba707f080d | |||
3816e01f87 | |||
548d215b48 | |||
43da58f214 | |||
f90d052538 | |||
13ff7cd0ec | |||
a3b34518b0 | |||
5a33dc8a81 | |||
7349e28898 | |||
26b9fdf40e | |||
3cf82b9be2 | |||
546c44bafa | |||
d727d3fcde | |||
6b0cf961c6 | |||
18419d763d | |||
99fdb53fa0 | |||
879fdd687e | |||
6c1b879c34 | |||
019bbc79fc | |||
f857a88541 | |||
6531e7bfbb | |||
2147225afd | |||
841ea6d060 | |||
3dddb2eb30 | |||
651cf14556 | |||
7f6fb5559b | |||
ea724038dc | |||
19757d4245 | |||
07a7b4048a | |||
45742aa2ac | |||
db0c5d9f9f | |||
8285250a1b | |||
de0257c7e9 | |||
3580012065 | |||
cdb23fffb6 | |||
6937c51549 | |||
69e90523e2 | |||
f76235736a | |||
8431243b63 | |||
458b4553d2 | |||
0f6e8854d8 | |||
5565bb7d24 | |||
6c539fb04f | |||
b30a0ced87 | |||
ac942e198a | |||
cef1f57e30 | |||
980ad6ce91 | |||
53bfea5752 | |||
4917bb7e39 | |||
139823203e | |||
883f4d1a20 | |||
0bce69edd0 | |||
efccc921cb | |||
55859b1237 | |||
ec09d40366 | |||
512e40fae3 | |||
028dac25f6 | |||
e0d4763974 | |||
3b3e402ffa | |||
e37ac1a1d7 | |||
17eb36a8dc | |||
10d44b97cc | |||
505c750dd0 | |||
d0e900606a | |||
dcbb076266 | |||
22c852f2d9 | |||
76770bc0e1 | |||
572080bc6d | |||
0b8142ae73 | |||
09a06d9fa9 | |||
80e8c6684d | |||
4cccb36f3d | |||
a427a1e720 | |||
be77c5296b | |||
a0c1b2c580 | |||
fc905c5f8f | |||
f1bd84733b | |||
d3080d2e66 | |||
090e530ff0 | |||
094e9d25cd | |||
0bcb9c16fa | |||
269bdb82a6 | |||
cba7e02bcd | |||
8ef834b73b | |||
ec54622f52 | |||
5d90b70425 | |||
8cef13e517 | |||
82986c091b | |||
67f2fdcfec | |||
d11c5a9028 | |||
b7cb7e477e | |||
0d1059aedf | |||
b92fc783fa | |||
6d73e5e129 | |||
6150850729 | |||
76a18fa61b | |||
2bd66ae4ef | |||
f6eefde27c | |||
60c9e4a82f | |||
56713227c5 | |||
fd6e110790 | |||
2336521df1 | |||
2ce72aeb28 | |||
e746c13212 | |||
9e073aee36 | |||
3906f06a2f | |||
d89747fa46 | |||
c4e6618baa | |||
5232be58ce | |||
5a75483811 | |||
4b40585690 | |||
dd65efaab6 | |||
890c2566af | |||
cd71fc5d13 | |||
f626dd4bbb | |||
956992e9ab | |||
91ddcef6ce | |||
49fa42473f | |||
564de8863a | |||
1dd70100d6 | |||
a38ff18eaf | |||
d46ef1efca | |||
c54cd21efa | |||
94f18340ec | |||
13bdcf762d | |||
6455da6adb | |||
4e88ba4ef2 | |||
0c7d49256d | |||
c2883d00ee | |||
7da483f258 | |||
6cbc6a53b2 | |||
5e23bc96ca | |||
4169663a8b | |||
4795c58e97 | |||
8fb96934ca | |||
cd91504c1f | |||
91e8196621 | |||
26841de6cf | |||
24f2a45310 | |||
67c5f0612a | |||
d7c3f1b50a | |||
2fb6025848 | |||
8da3c5eb84 | |||
4ee1799271 | |||
953ea31016 | |||
9fe27d5f35 | |||
d290aeb2e9 | |||
7fee84678a | |||
77030db1d3 | |||
bb6ae00a49 | |||
6515cc0360 | |||
13d09b3e83 | |||
3a434197a3 | |||
8ab0dc450a | |||
4afc887ee5 | |||
db4692843f | |||
ad98c1aaa6 | |||
6ff9652450 | |||
6182a80f41 | |||
06e59c8d02 | |||
b9f17c3143 | |||
10e3fdf007 | |||
9a50050f7c | |||
63ac41c4b4 | |||
602ebacb0b | |||
4e55c0439e | |||
965deb5711 | |||
c24aba739b |
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,6 +6,7 @@ temp
|
||||
projects
|
||||
win10/app/bin
|
||||
win10/app/bld
|
||||
win10/*.opendb
|
||||
|
||||
*.user
|
||||
*.sw?
|
||||
|
@ -13,4 +13,5 @@ notifications:
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
- built/cache
|
||||
|
||||
|
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"tslint.enable": true,
|
||||
"tslint.rulesDirectory": "node_modules/tslint-microsoft-contrib"
|
||||
}
|
@ -3,6 +3,8 @@
|
||||
This target allow to program a [BBC micro:bit](https://www.microbit.co.uk/) using
|
||||
[Microsoft Programming Experience Toolkit](https://github.com/Microsoft/pxt).
|
||||
|
||||
* [Try it live](https://m.pxt.io)
|
||||
|
||||
[](https://travis-ci.org/Microsoft/pxt-microbit)
|
||||
|
||||
# Getting started
|
||||
@ -12,7 +14,7 @@ Please follow instructions at https://github.com/Microsoft/pxt#running-a-target-
|
||||
## Universal Windows App
|
||||
|
||||
The Windows 10 app is a [Universal Windows Hosted Web App](https://microsoftedge.github.io/WebAppsDocs/en-US/win10/CreateHWA.htm)
|
||||
that wraps codemicrobit.com and provides additional features.
|
||||
that wraps m.pxt.io and provides additional features.
|
||||
|
||||
### Sideloading
|
||||
|
||||
@ -23,4 +25,4 @@ that wraps codemicrobit.com and provides additional features.
|
||||
### Building
|
||||
|
||||
* Install Visual Studio 2015 Update 2 or higher. Make sure the Windows 10 templates are installed.
|
||||
* open the ``win10/app.sln`` solution and launch the ``codemicrobit`` project.
|
||||
* open the ``win10/app.sln`` solution and launch the ``m.pxt.io`` project.
|
||||
|
22
docs/_locales/pl/_theme.json
Normal file
22
docs/_locales/pl/_theme.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "koduj z micro:bit",
|
||||
"title": "koduj z micro:bit",
|
||||
"docMenu": [
|
||||
{
|
||||
"name": "O nas",
|
||||
"path": "/about"
|
||||
},
|
||||
{
|
||||
"name": "Lekcje",
|
||||
"path": "/lessons"
|
||||
},
|
||||
{
|
||||
"name": "Instrukcja obsługi",
|
||||
"path": "/reference"
|
||||
},
|
||||
{
|
||||
"name": "Urządzenie",
|
||||
"path": "/device"
|
||||
}
|
||||
]
|
||||
}
|
7
docs/_locales/pl/docs.md
Normal file
7
docs/_locales/pl/docs.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Dokumentacja
|
||||
|
||||
Witamy na stronach dokumentacji!
|
||||
|
||||
* Przeglądnij [instrukcje obsługi](/reference)
|
||||
* Dowiedz się więcej o [urządzeniu](/device)
|
||||
* Wystartuj z [lekcjami](/lessons)
|
@ -69,7 +69,11 @@ When your micro:bit isn’t connected to your computer, tablet or mobile, you wi
|
||||
The pins labelled 3V and GND are the power supply pins.
|
||||
You can attach an external device such as a motor to these and power it using the battery or USB.
|
||||
|
||||
### Bluetooth Low Energy Antenna
|
||||
### Serial Communication
|
||||
|
||||
The BBC micro:bit can send an receive data via [serial communication](/device/serial). The serial data can be transfered via USB or BlE.
|
||||
|
||||
### Bluetooth Low Energy (BLE) Antenna
|
||||
|
||||
You will see the label BLE ANNTENA on the back of your micro:bit. It is for a messaging service,
|
||||
so that devices can talk to each other. The micro:bit is a peripheral
|
||||
|
@ -1,8 +1,7 @@
|
||||
# crocodile clips
|
||||
|
||||
The on pin pressed accessories.
|
||||
|
||||
Register an [event handler](/reference/event-handler) that will execute whenever the user attaches one side of the crocodile clip to the `GND` pin, then connects and disconnects the unattached side of the crocodile clip to pin `0`, `1`, or `2`.
|
||||
The large holes at the bottom of the board are designed to attach alligator/crocodile clips.
|
||||
Register an event that will execute whenever the user attaches one side of the crocodile clip to the `GND` pin, then connects and disconnects the unattached side of the crocodile clip to pin `0`, `1`, or `2`.
|
||||
|
||||
### Example: on pin pressed with random numbers
|
||||
|
||||
@ -12,9 +11,7 @@ This example displays a random number every time the crocodile clip holds `GND`
|
||||
|
||||
### Connecting Crocodile Clips
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
### Lessons
|
||||
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
The micro:bit LED screen
|
||||
|
||||

|
||||
```sim
|
||||
basic.showString(" ");
|
||||
```
|
||||
|
||||
The micro:bit LED screen consists of 25 red LED lights arranged in a 5X5 grid (5 LEDs across by 5 LEDs down).
|
||||
|
||||
@ -30,28 +32,38 @@ Since the row and column numbers start at 0, an easy way to figure out the x, y
|
||||
|
||||
### Turn a LED on/off
|
||||
|
||||
Use [plot](/led/plot) and [unplot](/led/unplot) to turn a LED on or off
|
||||
Use [plot](/reference/led/plot) and [unplot](/reference/led/unplot) to turn a LED on or off
|
||||
|
||||
```blocks
|
||||
led.plot(0,0)
|
||||
led.unplot(0,0)
|
||||
```
|
||||
|
||||
### Is a LED on/off?
|
||||
|
||||
Use the [point](/led/point) function to find out if a LED is on or off.
|
||||
Use the [point](/reference/led/point) function to find out if a LED is on or off.
|
||||
|
||||
```blocks
|
||||
if(led.point(0,0)) {
|
||||
}
|
||||
```
|
||||
|
||||
### Display images, strings and numbers
|
||||
|
||||
Instead of turning individual LEDs on or off, as above, you can display an [image](/reference/image/image) directly to the screen or show text/numbers on screen using the [show number](/reference/basic/show-number)/[show string](/reference/basic/show-string) function.
|
||||
Instead of turning individual LEDs on or off, as above, you can display an [image](/reference/images/image) directly to the screen or show text/numbers on screen using the [show number](/reference/basic/show-number)/[show string](/reference/basic/show-string) function.
|
||||
|
||||
### The display buffer
|
||||
|
||||
The micro:bit runtime keeps an in-memory representation of the state of all 25 LEDS. This state is known as the "display buffer" and controls which LEDS are on and which are off. The plot/unplot/point functions access the display buffer directly. On the other hand, the functions that show an image, number or string overwrite the buffer completely. To illustrate, first try running this code sequence
|
||||
|
||||
```
|
||||
basic.showString("d", 150)
|
||||
```blocks
|
||||
basic.showString("d")
|
||||
led.plot(0, 0)
|
||||
```
|
||||
|
||||
You will see the letter "d" displayed as well as the LED in position `0,0` lit up. Now try reversing the order of the two statements above:
|
||||
|
||||
```
|
||||
```blocks
|
||||
led.plot(0, 0)
|
||||
basic.showString("d", 150)
|
||||
```
|
||||
|
64
docs/device/serial.md
Normal file
64
docs/device/serial.md
Normal file
@ -0,0 +1,64 @@
|
||||
# Serial
|
||||
|
||||
The [serial](/reference/serial) supports [serial communication](https://en.wikipedia.org/wiki/Serial_port) between the BBC micro:bit and another computer. Basically, this allows you to send data from the micro:bit to your own computer. This is very useful for debugging purposes: you can add `write line` statements in your code and see them display on your computer as the program executes.
|
||||
|
||||
The code below shows a simple script that sends a line when the BBC micro:bit starts and another line each time the button ``A`` is pressed.
|
||||
|
||||
```blocks
|
||||
serial.writeLine("started...")
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
serial.writeLine("A pressed")
|
||||
})
|
||||
```
|
||||
|
||||
## How to read the micro:bit's serial output from your computer
|
||||
|
||||
Unfortunately, using the serial library requires quite a bit of a setup.
|
||||
|
||||
### Windows
|
||||
|
||||
You must install a device driver (for the computer to recognize the serial interface of the micro:bit); then, you must also install a terminal emulator (which is going to connect to the micro:bit and read its output). Here's how to do it:
|
||||
|
||||
* Follow instructions at https://developer.mbed.org/handbook/Windows-serial-configuration in order to install the device driver
|
||||
* Install a terminal emulator; we recommend [Tera Term](https://ttssh2.osdn.jp/index.html.en). At the time of this writing, the latest version is 4.88 and can be downloaded [from here](http://en.osdn.jp/frs/redir.php?m=jaist&f=%2Fttssh2%2F63767%2Fteraterm-4.88.exe). Follow the instructions from the installer.
|
||||
|
||||
Once both the driver and the terminal emulator are installed, plug in the micro:bit and wait until the device is fully setup. Then, open TeraTerm.
|
||||
|
||||
* Hit `File` > `New Connection`
|
||||
* Check "Serial"; in the dropdown menu, pick the COM port that says "mbed Serial Port". Hit `Ok`.
|
||||
* In the menus, hit `Setup` > `Serial Port` and set the baud rate to `115200`.
|
||||
|
||||
You should be good. Feel free to hit `Setup` > `Save Setup` in the menus to erase the default configuration file with a new one so that you don't have to type in the settings again.
|
||||
|
||||
Please note that Windows will assign you a different COM port if you plug in another micro:bit. If you're juggling between micro:bits, you'll have to change the COM port every time.
|
||||
|
||||
### Alternative Windows setup with Putty
|
||||
|
||||
If you prefer another terminal emulator (such as [PuTTY](http://www.putty.org/)), here are some instructions.
|
||||
|
||||
* Open Windows's [Device Manager](https://windows.microsoft.com/en-us/windows/open-device-manager); expand the section called "Ports (COM & LPT)"; write down the com number for "mbed Serial Port" (e.g. COM14)
|
||||
* Open PuTTY; on the main screen, use the following settings: Serial / COM14 / 115200. Replace COM14 with the COM port number you wrote down previously. Feel free to type in a name and hit "Save" to remember this configuration.
|
||||
|
||||

|
||||
|
||||
* (optional): in the "Terminal" section, check "implicit cr in every lf"
|
||||
|
||||

|
||||
|
||||
### Linux
|
||||
|
||||
(Untested).
|
||||
|
||||
* Plug in the micro:bit
|
||||
* Open a terminal
|
||||
* `dmesg | tail` will show you which `/dev/` node the micro:bit was assigned (e.g. `/dev/ttyUSB0`)
|
||||
* Then, do: `screen /dev/ttyUSB0 115200` (install the `screen` program if you don't have it). To exit, run `Ctrl-A` `Ctrl-D`.
|
||||
|
||||
Alternative programs include minicom, etc.
|
||||
|
||||
### Mac OS
|
||||
|
||||
* Plug in the micro:bit
|
||||
* Open a terminal
|
||||
* `ls /dev/cu.*` will return to you a list of serial devices; one of them will look like `/dev/cu.usbmodem1422` (the exact number depends on your computer)
|
||||
* `screen /dev/cu.usbmodem1422 115200` will open up the micro:bit's serial output. To exit, hit `Ctrl-A` `Ctrl-D`.
|
25
docs/device/simulator.md
Normal file
25
docs/device/simulator.md
Normal file
@ -0,0 +1,25 @@
|
||||
# Simulator
|
||||
|
||||
The JavaScript simulator allows to test and execute most BBC micro:bit programs in the browser.
|
||||
It allows to emulate sensor data or user interactions.
|
||||
|
||||
```sim
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("A");
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showString("B");
|
||||
});
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.showString("0");
|
||||
});
|
||||
input.onPinPressed(TouchPin.P1, () => {
|
||||
basic.showString("1");
|
||||
});
|
||||
input.onPinPressed(TouchPin.P2, () => {
|
||||
basic.showString("2");
|
||||
});
|
||||
input.temperature()
|
||||
input.compassHeading()
|
||||
input.lightLevel()
|
||||
```
|
@ -2,7 +2,7 @@
|
||||
|
||||
How to compile, transfer, and run a script on your micro:bit.
|
||||
|
||||
While you're writing and testing your Block Editor or Touch Develop scripts, you'll mostly be running scripts in your browser by clicking the `Run` button (see [run code in your browser](/js/simulator) for info about this).
|
||||
While you're writing and testing your Block Editor or Touch Develop scripts, you'll mostly be running scripts in your browser by clicking the `Run` button (see [run code in your browser](/device/simulator) for info about this).
|
||||
|
||||
Once your masterpiece is complete, you can compile your script and run it on your micro:bit.
|
||||
|
||||
@ -31,12 +31,6 @@ Windows
|
||||
Mac (picture bvabdbco)
|
||||
WARN: unknown picture: bvabdbco:5x3
|
||||
|
||||
### ~hide
|
||||
|
||||
If your computer doesn't recognise your micro:bit, please see [troubleshooting USB problems](/diagnosing-usb).
|
||||
|
||||
### ~
|
||||
|
||||
## Step 2: Compile your script
|
||||
|
||||
Next, compile your script:
|
||||
@ -133,5 +127,5 @@ Or it may appear that there are two hex files on your micro:bit so the micro:bit
|
||||
|
||||
### See also
|
||||
|
||||
[Run code in a browser](/js/simulator)
|
||||
[Run code in a browser](/device/simulator)
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
Welcome to the documentation.
|
||||
|
||||
* Browse the [reference](/reference)
|
||||
* Browse the [API reference](/reference)
|
||||
* Learn more about the [device](/device)
|
||||
* Get started with [lessons](/lessons)
|
||||
* Learn about [libraries](/libraries) (possibly using C++)
|
||||
|
@ -57,8 +57,10 @@
|
||||
* [Telegraph](/lessons/telegraph), play the telegraph game between two BBC micro:bits
|
||||
* [Pogo](/lessons/pogo), create a pogo game to test your jumping abilities
|
||||
|
||||
## Science
|
||||
* [Charting](/lessons/charting), measure and chart acceleration
|
||||
|
||||
## Advanced
|
||||
* [Charting](/lessons/charting), create a charting app between 2 BBC micro:bits
|
||||
* [Prank WiFi](/lessons/prank-wifi), create fake WiFi to trick your friends
|
||||
* [Speed Button](/lessons/speed-button), code a speed game with running time
|
||||
* [Headbands](/lessons/headbands), create a charades game with a collection of strings that hold the words
|
||||
@ -68,5 +70,4 @@
|
||||
|
||||
### @section full
|
||||
|
||||
The lessons promote computational thinking and computer science literacy[ read more...](/lessons/teach)
|
||||
|
||||
The lessons promote computational thinking and computer science literacy[ read more...](/lessons/teach)
|
@ -21,7 +21,6 @@ basic.showString("ASK ME A QUESTION")
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("Yes")
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
* `Run` the code to see if it works as expected.
|
||||
@ -45,7 +44,6 @@ input.onButtonPressed(Button.B, () => {
|
||||
|
||||
* `Run` the code to see if it works as expected.
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
When you are asked a yes or no question, do you always say yes or no? Add a condition for `on shake` that displays `MAYBE`.
|
||||
### Challenge 3
|
||||
|
||||
When you are asked a yes or no question, do you always say yes or no? Add a condition for `on shake` that displays `MAYBE`.
|
@ -12,7 +12,6 @@ Answers may vary. This is a function that will show a string on the LED screen o
|
||||
|
||||
```blocks
|
||||
basic.showString("Y")
|
||||
|
||||
```
|
||||
|
||||

|
||||
@ -22,7 +21,6 @@ basic.showString("Y")
|
||||
|
||||
```blocks
|
||||
basic.showString("Hi")
|
||||
|
||||
```
|
||||
|
||||

|
||||
@ -35,7 +33,6 @@ basic.showString("Hi")
|
||||
|
||||
```blocks
|
||||
basic.showString("Z")
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
@ -79,7 +79,18 @@ Your banana keyboard is ready!
|
||||
|
||||
### Step 10
|
||||
|
||||
Connect your micro:bit to your computer using your USB cable and run the [banana keyboard](/lhpkbr) script on it. Tap your banana instrument to play sound against... the fruit!
|
||||
Connect your micro:bit to your computer using your USB cable and run this script:
|
||||
```blocks
|
||||
let sound = music.noteFrequency(Note.C);
|
||||
input.onPinPressed(TouchPin.P1, () => {
|
||||
for (let i = 0; i < 5; i++) {
|
||||
sound = sound + 25;
|
||||
music.playTone(sound, music.beat(BeatFraction.Sixteenth));
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Tap your banana instrument to play sound against... the fruit!
|
||||
|
||||
|
||||
### ~avatar boothing
|
||||
|
@ -1,22 +0,0 @@
|
||||
# beatbox blocks lesson
|
||||
|
||||
display beautiful images on the BBC micro:bit.
|
||||
|
||||
## Topic
|
||||
|
||||
Music
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/beatbox/activity)
|
||||
* [challenges](/lessons/beatbox/challenges)
|
||||
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to make a beatbox music player using pins P1 and P2. We will be learning how to code musical notes using a local variable, for loop, on pin pressed as well as simple commands such as play and notes.
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to code music on the BBC micro:bit
|
||||
|
@ -39,9 +39,9 @@ basic.showLeds(`
|
||||
`)
|
||||
```
|
||||
|
||||
* *Run* your code to see if it works as expected.
|
||||
* Does your code work as expected?
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Nice job! Why don't we create a third image that will show after the other two? Remember to add a pause before you create and show the image.
|
||||
Nice job! Why don't we create a third image that will show after the other two?
|
||||
|
||||
|
@ -6,23 +6,20 @@ a game where you have to keep up with the commands.
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [bop it tutorial](/lessons/bop-it/tutorial).
|
||||
Use this activity document to guide your work in the [bop it activity](/lessons/bop-it/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the code that will store the global variable named 'action' and returns a random number between 0 and 2
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
action = Math.random(3)
|
||||
```blocks
|
||||
let action = Math.random(3)
|
||||
```
|
||||
|
||||
## 2. Write the code that will display the string, "PUSH A" if the global variable called 'action' is equal to 0
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
```blocks
|
||||
let action = Math.random(3)
|
||||
if (action == 0) {
|
||||
basic.showString("PUSH A", 150)
|
||||
}
|
||||
@ -30,10 +27,9 @@ if (action == 0) {
|
||||
|
||||
## 3. Write the code that increments the score if button A is pressed when the global variable called 'action' is equal to 1
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let action = Math.random(3)
|
||||
if (action == 0) {
|
||||
game.addScore(1)
|
||||
}
|
||||
@ -42,9 +38,8 @@ input.onButtonPressed(Button.A, () => {
|
||||
|
||||
## 4. Write the code that will display the string "LOGO DOWN" if the global variable called 'action' is equal to 1
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
```blocks
|
||||
let action = Math.random(3)
|
||||
if (action == 1) {
|
||||
basic.showString("LOGO DOWN", 150)
|
||||
}
|
||||
@ -52,10 +47,9 @@ if (action == 1) {
|
||||
|
||||
## 5. Write the code that increments the score if the BBC micro:bit logo is tilted down when the global variable called 'action' is equal to 1
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
```blocks
|
||||
input.onLogoDown(() => {
|
||||
let action = Math.random(3)
|
||||
if (action == 1) {
|
||||
game.addScore(1)
|
||||
}
|
||||
@ -64,9 +58,8 @@ input.onLogoDown(() => {
|
||||
|
||||
## 6. Write the code that will display the string "SHAKE" if the global variable called 'action' is equal to 2
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
```blocks
|
||||
let action = Math.random(3)
|
||||
if (action == 2) {
|
||||
basic.showString("SHAKE", 150)
|
||||
}
|
||||
@ -74,13 +67,11 @@ if (action == 2) {
|
||||
|
||||
## 7. Write the code that increments the score if the BBC micro:bit is shaken when the global variable called 'action' is equal to 2
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
```blocks
|
||||
input.onLogoDown(() => {
|
||||
let action = Math.random(3)
|
||||
if (action == 1) {
|
||||
game.addScore(1)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -6,7 +6,7 @@ a game where you have to keep up with the commands.
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [bop it tutorial](/lessons/bop-it/tutorial).
|
||||
Use this activity document to guide your work in the [bop it activity](/lessons/bop-it/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
|
@ -1,81 +0,0 @@
|
||||
# buzzer lesson
|
||||
|
||||
design a blinking image lesson #docs
|
||||
|
||||
## Topic
|
||||
|
||||
Ring
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/buzzer/activity)
|
||||
* [challenges](/lessons/buzzer/challenges)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning / place of lesson in scheme of work
|
||||
|
||||
Learn how to **ring** the buzzer to turn on the sound. We will be learning basic comments such as ring and clear screen.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **ring** : [read more...](/reference/music/ring)
|
||||
* **clear screen** : [read more...](/reference/basic/clear-screen)
|
||||
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to ring the BBC micro:bit
|
||||
* learn how to clear the screen
|
||||
* learn how to run code when an input button is pressed
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Recognises that different algorithms exist for the same problem (AL) (GE)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information(AB)
|
||||
|
||||
#### Hardware & Processing
|
||||
|
||||
* Understands the difference between hardware and application software, and their roles within a computer system (AB)
|
||||
|
||||
#### Communication Networks
|
||||
|
||||
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns (AL)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [activity](/lessons/buzzer/activity)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/lessons/buzzer/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/lessons/buzzer/challenges)
|
||||
|
@ -11,6 +11,7 @@ Variables
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/catch-the-egg-game/activity)
|
||||
* [tutorial](/lessons/catch-the-egg-game/tutorial)
|
||||
* [quiz](/lessons/catch-the-egg-game/quiz)
|
||||
* [quiz answers](/lessons/catch-the-egg-game/quiz-answers)
|
||||
|
||||
@ -20,18 +21,21 @@ Learn how to create a catch the egg game game with **plot**, `led->plot` , **unp
|
||||
|
||||
## Documentation
|
||||
|
||||
* **variables** : [read more...](/reference/variables/var)
|
||||
* **forever** : [read more...](/reference/basic/forever)
|
||||
* **unplot** : [read more...](/reference/led/unplot)
|
||||
* **plot** : [read more...](/reference/led/plot)
|
||||
* **if** : [read more...](/reference/logic/if)
|
||||
* **acceleration** : [read more...](/reference/input/acceleration)
|
||||
* **math minimum number** : [read more...](/js/math)
|
||||
* **math maximum number** : [read more...](/js/math)
|
||||
* **math random number** : [read more...](/js/math)
|
||||
* **math modulus** : [read more...](/js/math)
|
||||
* **show number** : [read more...](/reference/basic/show-number)
|
||||
* **pause** : [read more...](/reference/basic/pause)
|
||||
```cards
|
||||
let x = 2;
|
||||
led.unplot(0, 0);
|
||||
basic.forever(() => {});
|
||||
x += 1;
|
||||
led.plot(0, 0);
|
||||
basic.pause(300);
|
||||
input.acceleration(Dimension.X);
|
||||
Math.min(0,0);
|
||||
Math.max(0,1);
|
||||
Math.random(5);
|
||||
game.addScore(1);
|
||||
game.score();
|
||||
game.removeLife(1);
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
# catch the egg game challenges
|
||||
|
||||
Coding challenges for catch the egg game.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Your starting code should look like this:
|
||||
|
@ -6,7 +6,7 @@ Programming a game of catch the egg using the accelerometer
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [catch the egg tutorial](/lessons/catch-the-egg-game/tutorial)
|
||||
Use this activity document to guide your work in the [catch the egg activity](/lessons/catch-the-egg-game/activity)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
|
29
docs/lessons/catch-the-egg-game/tutorial.md
Normal file
29
docs/lessons/catch-the-egg-game/tutorial.md
Normal file
@ -0,0 +1,29 @@
|
||||
# catch the egg game tutorial
|
||||
|
||||
### Rebuild the game!
|
||||
|
||||
The blocks have been shuffled! Put them back together so that...
|
||||
* an egg LED falls from the top of the screen, row by row.
|
||||
* a basket LED is on the bottom row and can be moved by using the accelerometer `X` data.
|
||||
* if the egg LED reaches the last row, reset the egg position to the first row.
|
||||
|
||||
```shuffle
|
||||
let basketX = 2
|
||||
let eggX = 2
|
||||
let eggY = 0
|
||||
basic.forever(() => {
|
||||
led.unplot(basketX, 4)
|
||||
led.unplot(eggX, eggY)
|
||||
eggY = eggY + 1
|
||||
led.plot(eggX, eggY)
|
||||
basic.pause(300)
|
||||
let accX = input.acceleration(Dimension.X)
|
||||
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
|
||||
led.plot(basketX, 4)
|
||||
if (eggY > 4) {
|
||||
eggY = -1
|
||||
eggX = Math.random(5)
|
||||
}
|
||||
basic.pause(300)
|
||||
})
|
||||
```
|
@ -1,15 +1,16 @@
|
||||
# charting lesson
|
||||
|
||||
Measure the acceleration on the micro:bit in the "z" direction.
|
||||
Create a charting app for simulating and measuring the acceleration applied to the micro:bit
|
||||
|
||||
## Topic
|
||||
|
||||
Acceleration
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/charting/activity)
|
||||
|
||||
* [activity](/lessons/charting/acceleration)
|
||||
* [challenge](/lessons/charting/challenge)
|
||||
* [quiz](/lessons/charting/quiz)
|
||||
* [answers](/lessons/charting/quiz-answers)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
@ -18,9 +19,9 @@ Learn the functions of **on data received**, **send number** and **receive numbe
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
basic.showNumber(0)
|
||||
input.acceleration(Dimension.X)
|
||||
led.plotBarGraph(0, 1023)
|
||||
basic.showNumber(0)
|
||||
radio.onDataReceived(() => {})
|
||||
radio.sendNumber(0)
|
||||
radio.receiveNumber()
|
||||
|
@ -1,53 +1,85 @@
|
||||
# charting activity
|
||||
# Activity
|
||||
|
||||
Measure the acceleration on the micro:bit in the "z" direction.
|
||||
Measure the acceleration on the micro:bit in the "x" direction.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This activity will teach how to use the micro:bit to chart the acceleration in the "x" direction. Let's get started!
|
||||
|
||||
|
||||
### ~
|
||||
Let's measure `acceleration (mg)` in the "x" direction. Get the acceleration value (milli g-force), in one of three specified dimensions.
|
||||
|
||||
|
||||
```blocks
|
||||
input.acceleration(Dimension.X)
|
||||
|
||||
```
|
||||
|
||||
### ~
|
||||
Use the plot bar chart to visualize the acceleration on the LED screen of the micro:bit in the specified range. You implement plot Bar Graph to display a vertical bar graph based on the "value" and "high" value. Then you must insert acceleration in the X dimension to measure the acceleration.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plotBarGraph(input.acceleration(Dimension.X), 0)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
### ~
|
||||
Notice that moving the micro:bit in the simulator from left to right (x direction) changes the values beneath the micro:bit in a range from 1023 to -1023 as measured in milli-gravities. By hovering over the micro:bit from left to right, you can observe changing values beneath the micro:bit simulator. Also, the LEDs shown on the Bar Graph fluctates based on the movement of the micro:bit simulator in the x direction. The line underneath the micro:bit simulator reflect the acceleration in the x direction.
|
||||
|
||||
NOTE: The colors of the charts reflect the color of the micro:bit simulator. In this instance, the micro:bit is yellow. So the color of the data line reflects the color of the micro:bit
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
|
||||
Vigorously move the micro:bit in the micro:bit simulatator by moving the micro:bit image from side to side. Every time the micro:bit moves in the x direction in the simulator, you are generating data points that can be reviewed in Excel. The more attempts to move the micro:bit from side to side, the more data being saved in Excel. After you have vigarously moved the micro:bit simulator from side to side for a sufficient amount of time, you are ready to graph or chart the accceleration of the micro:bit. We want a printout of our acceleration on Excel that can be graphed in Excel.
|
||||
|
||||
### ~
|
||||
|
||||
Welcome! This activity will teach how to use the 1st micro:bit to chart the second micro:bit's acceleration in the "x" direction. Let's get started!
|
||||
We want to chart the data collected by using a tool in Excel.
|
||||
|
||||
Let's measure `acceleration (mg)` and then `send number`. `Acceleration` is measured in **milli-gravities**, so a value of -1000 is equivalent to -1g or -9.81m/s^2. We will be able to get the acceleration value (g-force), in the specified "x" dimension. `Send number` will broadcast a number data packet to other micro:bits connected via radio.
|
||||
|
||||
```blocks
|
||||
radio.sendNumber(input.acceleration(Dimension.X));
|
||||
```
|
||||
|
||||
We want to display the acceleration forever. In order to do so, we need a `forever` loop. A forever loop will repeat code in the background forever.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X));
|
||||
});
|
||||
The final part of this experiment is opening and reviewing the data in the Excel CSV file. Simply click on the line beneath the simulator. A CSV file will be generated to display the data points collected by moving the micro:bit in the X direction. Then click or tap on the data Excel file that was downloaded to your local Downloads Folder.
|
||||
|
||||
|
||||
```
|
||||
|
||||
We want to register code to run when a packet is received over radio. We can implement this code by adding `on data received`.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X))
|
||||
})
|
||||
radio.onDataReceived(() => {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
Finally, we want to chart the acceleration. So we must first implement `plot bar graph`. `Plot Bar Graph` will display a vertical bar graph based on the value and high value. In order to transfer the receive the number from the 1st micro:bit, we must implement `receive number` to constantly display a vertical bar graph based on the value. Remember, the value will equal to the micro:bit's acceleration in the "x" direction.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X))
|
||||
})
|
||||
radio.onDataReceived(() => {
|
||||
led.plotBarGraph(radio.receiveNumber(), 1023)
|
||||
})
|
||||
|
||||
```
|
||||
### ~
|
||||
|
||||
|
||||
* Connect the first micro:bit to your computer using your USB cable and run the charting script on it.
|
||||
* Connect the second micro:bit to your computer using your USB cable and run the charting script on it.
|
||||
* The first person and second person take turns tilting the micro:bit in the "x" direction while the other player charts the data on the micro:bit!
|
||||
First, click or tap on the first two columns (A, B) to include the time of the data being collected; b) the results of acceleration data on the micro:bit
|
||||
|
||||

|
||||
|
||||
Use the Recommended Charts command on the Insert tab to quickly create a chart that’s just right for your data.
|
||||
|
||||
* Select the data that you want to include in your chart.
|
||||
|
||||
* Click Insert > Recommended Charts.
|
||||
|
||||

|
||||
|
||||
* On the Recommended Charts tab, scroll through the list of chart types that Excel recommends for your data.
|
||||
|
||||
Click any chart type to see how your data will look in that format.
|
||||
|
||||
When you find the chart type that you want, click it, and then click OK. We want to select the chart called Line. A line chart is used to display trends over time. We will use the line chart because there are many data points over time.
|
||||
|
||||
Tip: If you don’t see a chart type that you want, click the All Charts tab to see all of the available chart types.
|
||||
|
||||

|
||||
|
||||
* Use the Chart Elements, Chart Styles, and Chart Filters buttons next to the upper-right corner of the chart to add chart elements like axis titles or data labels, to customize the look of your chart
|
||||
|
||||

|
||||
|
||||
* Connect a micro:bit to your computer using your USB cable; compile; and repeat this experiment by moving the micro:bit in the "x" direction. Then collect and chart the data on Excel.
|
||||
* Review and analyze the actual micro:bit device data on Excel
|
||||
* Display acceleration with y or z using plot bar graph by changing acceleration from "x" to "y" or "z"
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/charting/acceleration-challenge)
|
||||
|
||||
### ~
|
||||
|
||||
|
94
docs/lessons/charting/challenge.md
Normal file
94
docs/lessons/charting/challenge.md
Normal file
@ -0,0 +1,94 @@
|
||||
# Challenge
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! The activity will teach you how to use the acceleration of the 1st micro:bit and to visualize the acceleration on the 2nd micro:bit. Let's get started!
|
||||
|
||||
### ~
|
||||
Let's measure `acceleration (mg)` and then `send number`. `Acceleration` is measured in **milli-gravities**, so a value of -1000 is equivalent to -1g or -9.81m/s^2. We will be able to get the acceleration value (g-force), in the specified "x" dimension. `Send number` will broadcast a number data packet to other micro:bits connected via radio.
|
||||
|
||||
```blocks
|
||||
radio.sendNumber(input.acceleration(Dimension.X));
|
||||
```
|
||||
### ~
|
||||
We want to display the acceleration forever. In order to do so, we need a `forever` loop. A forever loop will repeat code in the background forever.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X));
|
||||
});
|
||||
|
||||
|
||||
```
|
||||
### ~
|
||||
We want to register code to run when a packet is received over radio. We can implement this code by adding `on data received`.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X))
|
||||
})
|
||||
radio.onDataReceived(() => {
|
||||
|
||||
})
|
||||
```
|
||||
### ~
|
||||
Finally, we want to chart the acceleration. So we must first implement `plot bar graph`. `Plot Bar Graph` will display a vertical bar graph based on the value and high value. In order to transfer the receive the number from the 1st micro:bit, we must implement `receive number` to constantly display a vertical bar graph based on the value. Remember, the value will equal to the micro:bit's acceleration in the "x" direction.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X))
|
||||
})
|
||||
radio.onDataReceived(() => {
|
||||
led.plotBarGraph(radio.receiveNumber(), 1023)
|
||||
})
|
||||
|
||||
```
|
||||
### ~
|
||||
Notice that moving the micro:bit the farthest direction in the x direction will be -1023 on the charting beneath the simulator. The second observation will be that the LEDs will be full brightness on the 2nd micro:bit. There is a single LED turned on with the 1st micro:bit. Additionally, the graphs will reflect 0 acceleation for the 1st micro:bit. In this scenario, if you are adjusting the acceleration in the simualator, you are also changing your chart that will be produced.
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
NOTE: The colors of the charts reflect the color of the micro:bit simulator. In this instance, the micro:bits are blue and green. So the colors of the line graphs reflect the colors of the micro:bit
|
||||
|
||||
### ~
|
||||
After running this simulatation several seconds by moving the micro:bit side to side in the x direction, you are ready to graph or chart the accceleration of the micro:bit. We want a printout of our acceleration on Excel. We will graph the fluctuating acceleration of the simulation experiment.
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
Finally, you must open the Excel CSV file by clicking on the data.xls file that was downloaded to Downloads Folder.
|
||||
|
||||

|
||||
|
||||
Use the Recommended Charts command on the Insert tab to quickly create a chart that’s just right for your data.
|
||||
|
||||
* Select the data that you want to include in your chart.
|
||||
|
||||
* Click Insert > Recommended Charts.
|
||||
|
||||

|
||||
|
||||
* On the Recommended Charts tab, scroll through the list of chart types that Excel recommends for your data.
|
||||
|
||||
Click any chart type to see how your data will look in that format.
|
||||
|
||||
When you find the chart type that you want, click it, and then click OK. We want to select the chart called Line. A line chart is used to display trends over time. We will use the line chart because there are many data points over time.
|
||||
|
||||
Tip: If you don’t see a chart type that you want, click the All Charts tab to see all of the available chart types.
|
||||
|
||||

|
||||
|
||||
* Use the Chart Elements, Chart Styles, and Chart Filters buttons next to the upper-right corner of the chart to add chart elements like axis titles or data labels, to customize the look of your chart
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
Have fun reviewing your simulation and analyze the acceleration by chart the Excel data using Excel.
|
||||
|
||||
* Connect the first micro:bit to your computer using your USB cable and run the charting script on it.
|
||||
* Connect the second micro:bit to your computer using your USB cable and run the charting script on it.
|
||||
* The first person and second person take turns tilting the micro:bit in the "x" direction while the other player charts the data on the micro:bit!
|
||||
* Review and analyze the actual micro:bit device acceleration data on Excel
|
||||
* Display acceleration with y or z using plot bar graph by changing acceleration from "x" to "y" or "z"
|
||||
|
33
docs/lessons/charting/quiz-answers.md
Normal file
33
docs/lessons/charting/quiz-answers.md
Normal file
@ -0,0 +1,33 @@
|
||||
# charting quiz answers
|
||||
|
||||
Measure the acceleration on the micro:bit in the "x" direction.
|
||||
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [glowing pendulum activity](/lessons/charting/acceleration)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Why are you creating a 'forever' loop?
|
||||
|
||||
<br/>
|
||||
|
||||
We are creating a forever loop to constantly display the appropriate brightness on the LED display.
|
||||
|
||||
## 2. Write the line of code to measure the acceleration with respect to the "x" axis and display this value in a bar graph.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
led.plotBarGraph(input.acceleration(Dimension.X), 0)
|
||||
```
|
||||
|
||||
## 3. After vigarously moving the micro:bit from side to side along the "x" axis for a sufficient amount of time,insert the Excel graph for displaying a line chart used to display trends over time.
|
||||
|
||||
<br/>
|
||||
|
||||

|
||||
|
23
docs/lessons/charting/quiz.md
Normal file
23
docs/lessons/charting/quiz.md
Normal file
@ -0,0 +1,23 @@
|
||||
# charting quiz
|
||||
|
||||
Measure the acceleration on the micro:bit in the "x" direction.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [glowing pendulum tutorial](/lessons/glowing-pendulum/activity)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Why are you creating a 'forever' loop?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the line of code to measure the acceleration with respect to the "y" axis and store this value in a local variable called 'acceleration'.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. After vigarously moving the micro:bit from side to side along the "x" axis for a sufficient amount of time,insert the Excel graph for displaying a line chart used to display trends over time.
|
||||
|
||||
|
@ -4,7 +4,7 @@ Create sounds with variables.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the [beatbox](/lessons/beatbox/activity) activity and your code will look like this:
|
||||
Complete the [beatbox](/lessons/classic-beatbox/activity) activity and your code will look like this:
|
||||
|
||||
|
||||
```blocks
|
||||
@ -17,7 +17,7 @@ input.onPinPressed(TouchPin.P1, () => {
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
### Challenge 1
|
||||
|
||||
Let's include a second sound `on pin pressed` *P2*. To do this, you need to add the same blocks as the banana keyboard activity. However, you must change alter `on pin pressed` from P1 to P2. Additionally, you must *decrease* the frequency of the variable "sound" by 25. Modify your code so that your code looks like this
|
||||
|
||||
@ -42,7 +42,7 @@ input.onPinPressed(TouchPin.P2, () => {
|
||||
|
||||
* click *run* to see if the code works as expected.
|
||||
|
||||
**Challenge 2**
|
||||
### Challenge 2
|
||||
|
||||
Finally, we want images to be displayed with sounds `on pin pressed`. Add `show LEDs` blocks under `on pin pressed` P1 and P2.
|
||||
|
||||
|
@ -1,41 +0,0 @@
|
||||
# crocodile clip activity
|
||||
|
||||
Use the crocodile clips
|
||||
|
||||
# micro:bit crocodile clip
|
||||
|
||||

|
||||
|
||||
In this project, you will build a circuit with the micro:bit from crocodile clips. Project duration: 15 minutes.
|
||||
|
||||
## Materials
|
||||
|
||||
* micro:bit, battery holder and 2 AAA batteries
|
||||
* Crocodile clips
|
||||
|
||||
## Steps
|
||||
|
||||
### Step 1
|
||||
|
||||

|
||||
|
||||
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
|
||||
|
||||
### Step 2
|
||||
|
||||

|
||||
|
||||
Using the 1st crocodile clip, connect the unattached end of the crocodile clip onto the 0 pin on the micro:bit.
|
||||
|
||||
### Step 3
|
||||
|
||||

|
||||
|
||||
Disconnect the end of the crocodile clip from the 0 pin of the micro:bit.
|
||||
|
||||
Your circuit is complete!
|
||||
|
||||
### Step 10
|
||||
|
||||
Connect your micro:bit to your computer using your USB cable and run the [guess the number](/lhpkbr) script on it.
|
||||
|
@ -42,7 +42,7 @@ input.onButtonPressed(Button.B, () => {
|
||||
|
||||
* `Run` the code to see if it works as expected.
|
||||
|
||||
**Challenge 3**
|
||||
### Challenge 3
|
||||
|
||||
When you are asked a yes or no question, do you always say yes or no? Add a condition for `on shake` that displays `TRY AGAIN`.
|
||||
|
||||
|
@ -9,6 +9,7 @@ Acceleration
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/glowing-pendulum/activity)
|
||||
* [tutorial](/lessons/glowing-pendulum/tutorial)
|
||||
* [challenges](/lessons/glowing-pendulum/challenges)
|
||||
* [quiz](/lessons/glowing-pendulum/quiz)
|
||||
* [quiz answers](/lessons/glowing-pendulum/quiz-answers)
|
||||
|
@ -4,10 +4,29 @@ Construct a pendulum that glows using acceleration.
|
||||
|
||||
Welcome! This activity will teach how to construct a pendulum that glows using acceleration. Let's get started!
|
||||
|
||||
Turn on all the LEDs.
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
```
|
||||
|
||||
Create a **forever** loop that will constantly display the appropriate brightness on the LED display.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
basic.forever(() => {
|
||||
|
||||
})
|
||||
@ -15,9 +34,14 @@ basic.forever(() => {
|
||||
|
||||
Now let's measure the acceleration on the `y` axis and store that value in a variable. The `acceleration(y)` function will provide the value.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration(Dimension.Y);
|
||||
});
|
||||
@ -25,27 +49,56 @@ basic.forever(() => {
|
||||
|
||||
Since the micro:bit will be swinging back and forth, the acceleration will only be positive half of the time. Thus, to always get a positive value, we want to take the absolute value of the acceleration.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
let acceleration = 0;
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
basic.forever(() => {
|
||||
acceleration = input.acceleration(Dimension.Y);
|
||||
let acceleration = input.acceleration(Dimension.Y);
|
||||
acceleration = Math.abs(acceleration)
|
||||
});
|
||||
```
|
||||
|
||||
The function `acceleration(y)` returns a number between 0 and 1024. We want to use this value for the brightness of the micro:bit, but the `set brightness()` only accepts a value between 0 and 256. Thus, we need to divide the acceleration by 4 to ensure we will be in the appropriate range.
|
||||
|
||||

|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration(Dimension.Y);
|
||||
acceleration = Math.abs(acceleration);
|
||||
acceleration = acceleration / 4;
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
Now let's use our acceleration value to set the brightness on the micro:bit.
|
||||
|
||||

|
||||
|
||||
Let's show what the brightness of the micro:bit is by turning all the LEDs on!
|
||||
|
||||

|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration(Dimension.Y);
|
||||
acceleration = Math.abs(acceleration);
|
||||
acceleration = acceleration / 4;
|
||||
led.setBrightness(acceleration)
|
||||
});
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
|
@ -6,15 +6,31 @@ Coding challenges for the glowing pendulum tutorial.
|
||||
|
||||
Complete the following [glowing pendulum activity](/lessons/glowing-pendulum/activity) and your code should look like this:
|
||||
|
||||

|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration(Dimension.Y);
|
||||
acceleration = Math.abs(acceleration);
|
||||
acceleration = acceleration / 4;
|
||||
led.setBrightness(acceleration)
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
});
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||

|
||||
|
||||
Hold the micro:bit in your hand in a dark room. Move the micro:bit like a pendulum and produce a slow image that captures the pattern of the micro:bit LEDs.
|
||||
|
||||
**Challenge 2**
|
||||
### Challenge 2
|
||||
|
||||
Replace "y" in `acceleration(y)` with "x" or "z". Changing the axis will cause the micro:bit to measure the force in a different direction. What differences in the resulting pattern does this replacement make?
|
||||
|
||||
|
@ -6,7 +6,7 @@ construct a pendulum that glows using acceleration.
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [glowing pendulum tutorial](/lessons/glowing-pendulum/tutorial)
|
||||
Use this activity document to guide your work in the [glowing pendulum activity](/lessons/glowing-pendulum/activity)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
@ -44,13 +44,3 @@ let accelerationDivided = accelerationX / 4
|
||||
led.setBrightness(accelerationX)
|
||||
```
|
||||
|
||||
## 5. Write the code that tuns all the LEDs on (as the image displays below)
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
led.plotAll()
|
||||
```
|
||||
|
||||
|
@ -24,11 +24,4 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu
|
||||
|
||||
## 4. Write the code to include acceleration value question 3 to set the brightness on the BBC micro:bit.
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. Write the code that tuns all the LEDs on (as the image displays below)
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
|
29
docs/lessons/glowing-pendulum/tutorial.md
Normal file
29
docs/lessons/glowing-pendulum/tutorial.md
Normal file
@ -0,0 +1,29 @@
|
||||
# glowing pendulum block tutorial
|
||||
|
||||
The glowing pendulum changes the screen brightness based on the acceleration measured on the BBC micro:bit.
|
||||
|
||||
### Rebuild the game!
|
||||
|
||||
The blocks have been shuffled! Put them back together so that...
|
||||
* all LEDs are turned on
|
||||
* the BBC micro:bit repeats code **forever** that
|
||||
* reads the acceleration along the ``y`` axis,
|
||||
* calculate the absolute value of the acceleration
|
||||
* scales down the acceleration value by a factor of `4`
|
||||
* uses the scaled value to set the screen **brightness**
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration(Dimension.Y);
|
||||
acceleration = Math.abs(acceleration);
|
||||
acceleration = acceleration / 4;
|
||||
led.setBrightness(acceleration)
|
||||
});
|
||||
```
|
@ -1,30 +0,0 @@
|
||||
# glowing sword blocks lesson
|
||||
|
||||
make a glowing sword.
|
||||
|
||||
### @video td/videos/glowing-sword-0
|
||||
|
||||
## Topic
|
||||
|
||||
Fade Out
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/glowing-sword/activity)
|
||||
* [quiz](/lessons/glowing-sword/quiz)
|
||||
* [quiz answers](/lessons/glowing-sword/quiz-answers)
|
||||
* [challenges](/lessons/glowing-sword/challenges)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to manipulate an image through **fade out**, `fade out` to gradually decrease the LED screen brightness until the LED lights are turned off. We will be learning how to fade an image using simple commands, such as image create image, image show image, LED fade out, basic pause, and fade in.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **create image** : [read more...](/reference/images/create-image)
|
||||
* **show image** : [read more...](/reference/images/show-image)
|
||||
* **fade out** : [read more...](/reference/led/fade-out)
|
||||
* **pause** : [read more...](/reference/basic/pause)
|
||||
* **fade in** : [read more...](/reference/led/fade-in)
|
||||
|
||||
|
@ -11,6 +11,7 @@ Math - Pick Random
|
||||
## Quick links
|
||||
|
||||
* [activity](/lessons/guess-the-number/activity)
|
||||
* [tutorial](/lessons/guess-the-number/tutorial)
|
||||
* [challenges](/lessons/guess-the-number/challenges)
|
||||
* [quiz](/lessons/guess-the-number/quiz)
|
||||
* [quiz answers](/lessons/guess-the-number/quiz-answers)
|
||||
|
@ -19,12 +19,11 @@ input.onButtonPressed(Button.A, () => {
|
||||
|
||||
```
|
||||
|
||||
Create a local variable of type number `x` and set it to a random number using `pick random`. `pick random` 9 generates a random number between `0` and `09`.
|
||||
|
||||
Create a local variable of type number `x` and set it to a random number using `pick random`. `pick random` 9 generates a random number between `0` and `9`.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(9)
|
||||
let x = Math.random(10)
|
||||
})
|
||||
|
||||
```
|
||||
@ -34,7 +33,7 @@ Show the random number on the screen.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(9)
|
||||
let x = Math.random(10)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
|
||||
|
25
docs/lessons/guess-the-number/tutorial.md
Normal file
25
docs/lessons/guess-the-number/tutorial.md
Normal file
@ -0,0 +1,25 @@
|
||||
# guess the number tutorial
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
### @video td/videos/guess-the-number-0
|
||||
|
||||
This tutorial will help you create a guess the number game! Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
### Rebuild the game!
|
||||
|
||||
The blocks have been shuffled! Put them back together so that...
|
||||
* when the user presses button ``A``,
|
||||
* generate a random number
|
||||
* show the number on screen
|
||||
|
||||
|
||||
```shuffle
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(10)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
```
|
||||
|
@ -42,17 +42,17 @@ Learn how to create a charades game with **collections**, ` create -> Collection
|
||||
## Documentation
|
||||
|
||||
* **collection**
|
||||
* **global variables** : [read more...](/js/data)
|
||||
* **global variables** : [read more...](/reference/variables/globals.md)
|
||||
* **Boolean** : [read more...](/reference/types/boolean)
|
||||
* **on logo up** [read more...](/functions/on-logo-up)
|
||||
* **on screen down** [read more...](/functions/on-screen-down)
|
||||
* **on screen up** [read more...](/functions/on-screen-up)
|
||||
* **show string** : [read more...](/reference/basic/show-string)
|
||||
* **game library** : [read more...](/js/game-library)
|
||||
* **game library** : [read more...](/reference/game-library)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/lessons/headbands/tutorial)
|
||||
* Activity: [tutorial](/lessons/headbands/activity)
|
||||
* Activity: [quiz](/lessons/headbands/quiz)
|
||||
* Extended Activity: [challenges](/lessons/headbands/challenges)
|
||||
|
||||
@ -112,7 +112,7 @@ Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algor
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/lessons/headbands/tutorial)
|
||||
* [tutorial](/lessons/headbands/activity)
|
||||
* [quiz](/lessons/headbands/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
@ -35,5 +35,5 @@ basic.showNumber(14)
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Keep displaying multiples of 7 such as 21 and 28, but don't forget to add pauses between the numbers!
|
||||
Keep displaying multiples of 7 such as 21 and 28...
|
||||
|
||||
|
@ -9,6 +9,7 @@ If (Conditionals)
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/magic-8/activity)
|
||||
* [tutorial](/lessons/magic-8/tutorial)
|
||||
* [challenges](/lessons/magic-8/challenges)
|
||||
* [quiz](/lessons/magic-8/quiz)
|
||||
* [quiz answers](/lessons/magic-8/quiz-answers)
|
||||
|
@ -1,8 +1,6 @@
|
||||
# magic 8 activity
|
||||
|
||||
A fortune teller game on the micro:bit
|
||||
|
||||
Welcome! This tutorial will help you create a magic 8 ball on the micro:bit. Let's get started!
|
||||
Welcome! This activity will help you create a magic 8 ball on the micro:bit. Let's get started!
|
||||
|
||||
Show a string to instruct the user how to play Magic 8! The magic 8 ball can only answer true or false questions.
|
||||
|
||||
@ -32,16 +30,13 @@ input.onGesture(Gesture.Shake, () => {
|
||||
Create a variable of type number called **randomNumber**. Set **randomNumber** to a random number with a limit of 2. Remember the random function in the math library, picks a random number from 0 to the limit, but not including the limit unless it is 0.
|
||||
|
||||
```blocks
|
||||
|
||||
basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen()
|
||||
let randomNumber = Math.random(2)
|
||||
let randomNumber = Math.random(3)
|
||||
|
||||
});
|
||||
|
||||
|
||||
```
|
||||
|
||||
Create an if statement for the condition `if randomNumber = 2`. If **randomNumber** is 2, display the string 'Yes'
|
||||
@ -52,7 +47,7 @@ basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen();
|
||||
let randomNumber = Math.random(2);
|
||||
let randomNumber = Math.random(3);
|
||||
if (randomNumber == 2) {
|
||||
basic.showString("YES");
|
||||
}
|
||||
@ -68,7 +63,7 @@ basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen()
|
||||
let randomNumber = Math.random(2)
|
||||
let randomNumber = Math.random(3)
|
||||
if (randomNumber == 2) {
|
||||
basic.showString("YES")
|
||||
} else if (randomNumber == 1) {
|
||||
@ -84,7 +79,7 @@ basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen()
|
||||
let randomNumber = Math.random(2)
|
||||
let randomNumber = Math.random(3)
|
||||
if (randomNumber == 2) {
|
||||
basic.showString("YES")
|
||||
} else if (randomNumber == 1) {
|
||||
@ -106,14 +101,13 @@ basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen()
|
||||
let randomNumber = Math.random(2)
|
||||
let randomNumber = Math.random(3)
|
||||
if (randomNumber == 2) {
|
||||
basic.showString("YES")
|
||||
} else if (randomNumber == 1) {
|
||||
basic.showString("NO")
|
||||
} else {
|
||||
basic.showString("I DON'T KNOW")
|
||||
|
||||
}
|
||||
basic.showNumber(8)
|
||||
|
||||
|
@ -26,7 +26,7 @@ input.onGesture(Gesture.Shake, () => {
|
||||
```
|
||||
|
||||
|
||||
**Challenge 1**
|
||||
### Challenge 1
|
||||
|
||||
Now let's increase the number of responses the magic 8 ball can give. How about 5 responses instead? Let's change the limit of `pick random` to 4.
|
||||
|
||||
@ -49,7 +49,7 @@ input.onGesture(Gesture.Shake, () => {
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
### Challenge 2
|
||||
|
||||
Now have the magic 8 ball respond "Try again" if **randomNumber** is 3.
|
||||
|
||||
@ -73,7 +73,7 @@ input.onGesture(Gesture.Shake, () => {
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
### Challenge 3
|
||||
|
||||
Now what about if **randomNumber** is 4? Let's have the magic 8 ball respond "Definitely!".
|
||||
|
||||
|
@ -6,7 +6,7 @@ create a magic 8 ball on the BBC micro:bit.
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [magic 8 tutorial](/lessons/magic-8/tutorial).
|
||||
Use this activity document to guide your work in the [magic 8 activity](/lessons/magic-8/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
|
27
docs/lessons/magic-8/tutorial.md
Normal file
27
docs/lessons/magic-8/tutorial.md
Normal file
@ -0,0 +1,27 @@
|
||||
# Magic 8 tutorial
|
||||
|
||||
Show a string to instruct the user how to play Magic 8! The magic 8 ball can only answer questions with "YES", "NO", or "MAYBE"...
|
||||
|
||||
### Rebuild the game!
|
||||
|
||||
The blocks have been shuffled! Put them back together so that...
|
||||
* show "ASK A QUESTION" on the screen
|
||||
* when the micro:bit is shaken,
|
||||
* generate a random number between 0 and 2.
|
||||
* if the number is `2`, show "YES"
|
||||
* if the number is `1`, show "NO"
|
||||
* otherwise show "MAYBE"...
|
||||
|
||||
```shuffle
|
||||
basic.showString("ASK A QUESTION")
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let randomNumber = Math.random(3)
|
||||
if (randomNumber == 2) {
|
||||
basic.showString("YES")
|
||||
} else if (randomNumber == 1) {
|
||||
basic.showString("NO")
|
||||
} else {
|
||||
basic.showString("MAYBE")
|
||||
}
|
||||
})
|
||||
```
|
@ -30,8 +30,6 @@ input.onGesture(Gesture.LogoUp, () => {
|
||||
. . # . .
|
||||
`)
|
||||
})
|
||||
|
||||
|
||||
```
|
||||
|
||||
Run your code and try to turn around the micro:bit to see the **logo up** event in action!
|
||||
|
@ -46,7 +46,7 @@ input.onButtonPressed(Button.B, () => {
|
||||
```
|
||||
|
||||
|
||||
**Challenge 3**
|
||||
### Challenge 3
|
||||
|
||||
Add an event handler with `on shake` to change the LED brightness back to a `255`.
|
||||
|
||||
|
@ -88,7 +88,7 @@ input.onButtonPressed(Button.B, () => {
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
**Challenge 3**
|
||||
### Challenge 3
|
||||
|
||||
Now make sure the image does not go off the left side and if it does, prompt the user to push button `A`.
|
||||
|
||||
|
@ -6,7 +6,7 @@ shift an image horizontally across the display with offset.
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [offset image tutorial](/lessons/offset-image/tutorial).
|
||||
Use this activity document to guide your work in the [offset image activity](/lessons/offset-image/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
|
@ -42,7 +42,7 @@ basic.forever(() => {
|
||||
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
### Challenge 1
|
||||
|
||||
What if wanted to show the maximum connectivity of wifi instead of just 1, 3, or 4 bars?
|
||||
|
||||
@ -86,7 +86,7 @@ basic.forever(() => {
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
### Challenge 2
|
||||
|
||||
Let's add an **IF** at the bottom of your code that checks to see if `sum >= to 1200` **and** if `sum <1400`
|
||||
|
||||
@ -135,7 +135,7 @@ basic.forever(() => {
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
### Challenge 3
|
||||
|
||||
Now it's your turn! Be creative and change the Wifi meter images to your own wifi image you're sure will prank your friends by editing the lines that call `showLeds()`.
|
||||
|
||||
|
@ -6,7 +6,7 @@ create a fake wifi app to trick your friends.
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [prank WiFi tutorial](/lessons/prank-wifi/tutorial)
|
||||
Use this activity document to guide your work in the [prank WiFi activity](/lessons/prank-wifi/activity)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
|
@ -41,7 +41,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
### Challenge 1
|
||||
|
||||
Create an event handler for Button B.
|
||||
|
||||
@ -83,7 +83,7 @@ input.onButtonPressed(Button.B, () => {
|
||||
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
### Challenge 2
|
||||
|
||||
### @video td/videos/screen-wipe-2
|
||||
|
||||
@ -155,7 +155,7 @@ basic.showLeds(`
|
||||
```
|
||||
|
||||
|
||||
**Challenge 3**
|
||||
### Challenge 3
|
||||
|
||||
Show an animation that scrolls back up when you press button "B".
|
||||
|
||||
|
34
docs/lessons/seismograph.md
Normal file
34
docs/lessons/seismograph.md
Normal file
@ -0,0 +1,34 @@
|
||||
# Seismograph Lesson
|
||||
|
||||
Build a seismograph with household materials
|
||||
|
||||
## Topic
|
||||
|
||||
Acceleration & Analog Read Pin
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/seismograph/activity)
|
||||
* [challenge](/lessons/seismograph/challenges)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to **show LEDs** to turn on a LED light pattern on the LED screen. We will be learning basic comments such as show LEDs and pause.
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
basic.forever(() => {
|
||||
});
|
||||
led.plotBarGraph(input.acceleration(Dimension.Strength) - 1023, 0);
|
||||
led.plotBarGraph(pins.analogReadPin(AnalogPin.P0), 0);
|
||||
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to repeat code forever in the background
|
||||
* learn how to display a vertical bar graph based on the value.
|
||||
* learn how to return the sum of the two numbers
|
||||
* learn how to get acceleration value in milli-gravitys
|
||||
* learn how to read the connector value as analog as a value comprised between 0 and 1023
|
150
docs/lessons/seismograph/activity.md
Normal file
150
docs/lessons/seismograph/activity.md
Normal file
@ -0,0 +1,150 @@
|
||||
# Seismograph Activity
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
In this project, you will build your own seismograph.
|
||||
|
||||
## What you'll need:
|
||||
|
||||
* micro:bit
|
||||
* USB cable
|
||||
* Scissors
|
||||
* Glue gun
|
||||
* String
|
||||
* Cup (Plastic or Paper)
|
||||
* Magnet
|
||||
|
||||
Welcome! This activity will teach how to use the micro:bit to chart the strength of the acceleration. Let's get started!
|
||||
|
||||
1. Setup Cup: Use scissors to cut a usable window on the cup, which will be a square sized hole at the lid side of the cup. Use scissors to create a small hole in the center of the base of the cup.
|
||||
|
||||
2. Fasten Magnet: Fasten end of the string to the magnet with glue
|
||||
|
||||
3. Secure String: Fasten string to base of the cup and hang the remaining string outside the base of the cup.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Seismograph built, let's code!
|
||||
|
||||
### ~
|
||||
|
||||
4. Go to Codemicrobit.com
|
||||
|
||||
Click or tap Create Code
|
||||
Click or tap Block Editor
|
||||
|
||||
### ~
|
||||
|
||||
5.
|
||||
|
||||
We will measure `acceleration (mg)` in terms of strength. Get the acceleration value (milli g-force), as measured in strength.
|
||||
|
||||
```blocks
|
||||
input.acceleration(Dimension.Strength);
|
||||
```
|
||||
|
||||
### ~
|
||||
|
||||
6.
|
||||
|
||||
Use the plot bar chart to visualize the acceleration on the LED screen of the micro:bit in the specified range. You implement plot Bar Graph to display a vertical bar graph based on the "value" and "high" value. Then you must insert acceleration in based on strength.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plotBarGraph(input.acceleration(Dimension.Strength), 0);
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
### ~
|
||||
|
||||
7.
|
||||
|
||||
Finally, we subtract the gravity from acceleration strength.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plotBarGraph(input.acceleration(Dimension.Strength) - 1023, 0);
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
### ~
|
||||
|
||||
8.
|
||||
|
||||
Notice that making vibrating the object below the micro:bit changes the values and the line appears as a wave to display the value of the strength as measured in milli-gravities. By making the object below the micro:bit vibrate, you will observe changing values of the micro:bit. Also, the LEDs shown on the Bar Graph fluctates based on the movement of the micro:bit strength.
|
||||
|
||||
NOTE: The black color reflects the micro:bit device.
|
||||
|
||||

|
||||
|
||||
|
||||
### ~
|
||||
|
||||
9.
|
||||
|
||||
Vigorously move the micro:bit in the micro:bit simulatator by moving the micro:bit image from side to side. Every time the micro:bit moves in the x direction in the simulator, you are generating data points that can be reviewed in Excel. The more attempts to move the micro:bit from side to side, the more data being saved in Excel. After you have vigarously moved the micro:bit simulator from side to side for a sufficient amount of time, you are ready to graph or chart the accceleration of the micro:bit. We want a printout of our acceleration on Excel that can be graphed in Excel.
|
||||
|
||||
|
||||
### ~
|
||||
|
||||
10.
|
||||
|
||||
We want to chart the data collected by using a tool in Excel.
|
||||
|
||||
The final part of this experiment is opening and reviewing the data in the Excel CSV file. Simply click on the line beneath the simulator. A CSV file will be generated to display the data points collected by moving the micro:bit in the X direction. Then click or tap on the data Excel file that was downloaded to your local Downloads Folder.
|
||||
|
||||
|
||||
### ~
|
||||
|
||||
10.
|
||||
|
||||
|
||||
First, click or tap on the first two columns (A, B) to include the time of the data being collected; b) the results of acceleration data on the micro:bit
|
||||
|
||||

|
||||
|
||||
Use the Recommended Charts command on the Insert tab to quickly create a chart that’s just right for your data.
|
||||
|
||||
* Select the data that you want to include in your chart.
|
||||
|
||||
* Click Insert > Recommended Charts.
|
||||
|
||||
### ~
|
||||
|
||||
11.
|
||||
|
||||
|
||||

|
||||
|
||||
* On the Recommended Charts tab, scroll through the list of chart types that Excel recommends for your data.
|
||||
|
||||
Click any chart type to see how your data will look in that format.
|
||||
|
||||
When you find the chart type that you want, click it, and then click OK. We want to select the chart called Line. A line chart is used to display trends over time. We will use the line chart because there are many data points over time.
|
||||
|
||||
Tip: If you don’t see a chart type that you want, click the All Charts tab to see all of the available chart types.
|
||||
|
||||
### ~
|
||||
|
||||
12.
|
||||
|
||||

|
||||
|
||||
* Use the Chart Elements, Chart Styles, and Chart Filters buttons next to the upper-right corner of the chart to add chart elements like axis titles or data labels, to customize the look of your chart
|
||||
|
||||
### ~
|
||||
|
||||
13.
|
||||
|
||||

|
||||
|
||||
* Connect a micro:bit to your computer using your USB cable; compile; and repeat this experiment by vibrating the micro:bit. Then chart the data on Excel.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/seismograph/challenge)
|
||||
|
||||
### ~
|
||||
|
94
docs/lessons/seismograph/challenge.md
Normal file
94
docs/lessons/seismograph/challenge.md
Normal file
@ -0,0 +1,94 @@
|
||||
# Challenge
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! The activity will teach you how to use the acceleration of the 1st micro:bit and to visualize the acceleration on the 2nd micro:bit. Let's get started!
|
||||
|
||||
### ~
|
||||
Let's measure `acceleration (mg)` and then `send number`. `Acceleration` is measured in **milli-gravities**, so a value of -1000 is equivalent to -1g or -9.81m/s^2. We will be able to get the acceleration value (g-force), in the specified "x" dimension. `Send number` will broadcast a number data packet to other micro:bits connected via radio.
|
||||
|
||||
```blocks
|
||||
radio.sendNumber(input.acceleration(Dimension.X));
|
||||
```
|
||||
### ~
|
||||
We want to display the acceleration forever. In order to do so, we need a `forever` loop. A forever loop will repeat code in the background forever.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X));
|
||||
});
|
||||
|
||||
|
||||
```
|
||||
### ~
|
||||
We want to register code to run when a packet is received over radio. We can implement this code by adding `on data received`.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X))
|
||||
})
|
||||
radio.onDataReceived(() => {
|
||||
|
||||
})
|
||||
```
|
||||
### ~
|
||||
Finally, we want to chart the acceleration. So we must first implement `plot bar graph`. `Plot Bar Graph` will display a vertical bar graph based on the value and high value. In order to transfer the receive the number from the 1st micro:bit, we must implement `receive number` to constantly display a vertical bar graph based on the value. Remember, the value will equal to the micro:bit's acceleration in the "x" direction.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X))
|
||||
})
|
||||
radio.onDataReceived(() => {
|
||||
led.plotBarGraph(radio.receiveNumber(), 1023)
|
||||
})
|
||||
|
||||
```
|
||||
### ~
|
||||
Notice that moving the micro:bit the farthest direction in the x direction will be -1023 on the charting beneath the simulator. The second observation will be that the LEDs will be full brightness on the 2nd micro:bit. There is a single LED turned on with the 1st micro:bit. Additionally, the graphs will reflect 0 acceleation for the 1st micro:bit. In this scenario, if you are adjusting the acceleration in the simualator, you are also changing your chart that will be produced.
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
NOTE: The colors of the charts reflect the color of the micro:bit simulator. In this instance, the micro:bits are blue and green. So the colors of the line graphs reflect the colors of the micro:bit
|
||||
|
||||
### ~
|
||||
After running this simulatation several seconds by moving the micro:bit side to side in the x direction, you are ready to graph or chart the accceleration of the micro:bit. We want a printout of our acceleration on Excel. We will graph the fluctuating acceleration of the simulation experiment.
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
Finally, you must open the Excel CSV file by clicking on the data.xls file that was downloaded to Downloads Folder.
|
||||
|
||||

|
||||
|
||||
Use the Recommended Charts command on the Insert tab to quickly create a chart that’s just right for your data.
|
||||
|
||||
* Select the data that you want to include in your chart.
|
||||
|
||||
* Click Insert > Recommended Charts.
|
||||
|
||||

|
||||
|
||||
* On the Recommended Charts tab, scroll through the list of chart types that Excel recommends for your data.
|
||||
|
||||
Click any chart type to see how your data will look in that format.
|
||||
|
||||
When you find the chart type that you want, click it, and then click OK. We want to select the chart called Line. A line chart is used to display trends over time. We will use the line chart because there are many data points over time.
|
||||
|
||||
Tip: If you don’t see a chart type that you want, click the All Charts tab to see all of the available chart types.
|
||||
|
||||

|
||||
|
||||
* Use the Chart Elements, Chart Styles, and Chart Filters buttons next to the upper-right corner of the chart to add chart elements like axis titles or data labels, to customize the look of your chart
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
Have fun reviewing your simulation and analyze the acceleration by chart the Excel data using Excel.
|
||||
|
||||
* Connect the first micro:bit to your computer using your USB cable and run the charting script on it.
|
||||
* Connect the second micro:bit to your computer using your USB cable and run the charting script on it.
|
||||
* The first person and second person take turns tilting the micro:bit in the "x" direction while the other player charts the data on the micro:bit!
|
||||
* Review and analyze the actual micro:bit device acceleration data on Excel
|
||||
* Display acceleration with y or z using plot bar graph by changing acceleration from "x" to "y" or "z"
|
||||
|
@ -22,7 +22,7 @@ Learn how to declare a **Boolean** variable, `var t:= true` `var f:=false` for o
|
||||
## Documentation
|
||||
|
||||
* **running time** : [read more...](/reference/input/running-time)
|
||||
* **global variable** : [read more...](/js/data)
|
||||
* **global variable** : [read more...](/reference/variables/globals)
|
||||
* **Boolean** : [read more...](/reference/types/boolean)
|
||||
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
|
||||
* **if** : [read more...](/reference/logic/if)
|
||||
|
@ -6,7 +6,7 @@ a spin the BBC micro:bit game with the input on shake.
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [spinner tutorial](/lessons/spinner/tutorial).
|
||||
Use this activity document to guide your work in the [spinner activity](/lessons/spinner/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
|
@ -42,7 +42,7 @@ Overview of Blocks lessons for the BBC micro:bit.
|
||||
* [Truth or dare](/lessons/truth-or-dare), a game that forces each player to reveal a secret or do something funny with if statement
|
||||
* [Spinner](/lessons/spinner), spin the arrow with multiple if statements
|
||||
* [Die roll](/lessons/die-roll), spin with more if statements
|
||||
* [Beatbox](/lessons/beatbox), make a beatbox music player with variables
|
||||
* [Beatbox](/lessons/classic-beatbox), make a beatbox music player with variables
|
||||
* [Temperature](/lessons/temperature), get the ambient temperature (degree Celsius °C)
|
||||
|
||||
### ~
|
||||
|
@ -11,6 +11,7 @@ If (Conditionals)
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/truth-or-dare/activity)
|
||||
* [tutorial](/lessons/truth-or-dare/tutorial)
|
||||
* [challenges](/lessons/truth-or-dare/challenges)
|
||||
* [quiz](/lessons/truth-or-dare/quiz)
|
||||
* [quiz answers](/lessons/truth-or-dare/quiz-answers)
|
||||
|
63
docs/lessons/truth-or-dare/tutorial.md
Normal file
63
docs/lessons/truth-or-dare/tutorial.md
Normal file
@ -0,0 +1,63 @@
|
||||
# truth or dare tutorial
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
### @video td/videos/truth-or-dare-0
|
||||
|
||||
The *Truth or dare!* game works as follows: a player spins the BBC micro:bit on the table.
|
||||
When the micro:bit stops spinning, the player pointed by the arrow (displayed on screen) must press the button "A"
|
||||
to see if she has to provide a *truth* or a *dare*.
|
||||
|
||||
### ~
|
||||
|
||||
### Rebuild the game!
|
||||
|
||||
The blocks have been shuffled! Put them back together so that...
|
||||
* an up arrow is displayed when the micro:bit is powered on.
|
||||
* on button `A` is pressed,
|
||||
* randomly display "TRUTH" or "DARE" on the screen
|
||||
* show the up arrow again.
|
||||
|
||||
```shuffle
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
# # # # #
|
||||
. . # . .
|
||||
. . # . .
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let random = Math.random(2)
|
||||
if (random == 0) {
|
||||
basic.showString("TRUTH")
|
||||
} else {
|
||||
basic.showString("DARE")
|
||||
}
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
# # # # #
|
||||
. . # . .
|
||||
. . # . .
|
||||
`)
|
||||
})
|
||||
```
|
||||
### Hints and tips
|
||||
Cut out these documentation cards to help you!
|
||||
|
||||
```cards
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
# . # . #
|
||||
. . # . .
|
||||
. . # . .
|
||||
`);
|
||||
Math.random(2);
|
||||
basic.showString("TRUTH");
|
||||
if (true) {} else {}
|
||||
"TRUTH";
|
||||
0;
|
||||
input.onButtonPressed(Button.A, () => {});
|
||||
```
|
||||
|
14
docs/libraries.md
Normal file
14
docs/libraries.md
Normal file
@ -0,0 +1,14 @@
|
||||
# Extensions
|
||||
|
||||
You can publish libraries (also known as packages or extensions)
|
||||
that users can then add to their scripts. These typically
|
||||
provide a driver for a particular hardware device you can connect
|
||||
to a microbit.
|
||||
|
||||
* [Sample C++ extension](https://github.com/Microsoft/pxt-microbit-cppsample)
|
||||
* [Sample TypeScript extension](https://github.com/Microsoft/pxt-microbit/tree/master/libs/i2c-fram)
|
||||
|
||||
## Finding libraries
|
||||
|
||||
## Publishing libraries
|
||||
|
23
docs/microbit-reference.md
Normal file
23
docs/microbit-reference.md
Normal file
@ -0,0 +1,23 @@
|
||||
# microbit Reference
|
||||
|
||||
```namespaces
|
||||
basic.showNumber(0);
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
|
||||
});
|
||||
led.plot(0, 0);
|
||||
music.playTone(0, 0);
|
||||
game.addScore(1);
|
||||
images.createImage(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`);
|
||||
pins.digitalReadPin(DigitalPin.P0);
|
||||
serial.writeValue(x, 0);
|
||||
control.inBackground(() => {
|
||||
|
||||
});
|
||||
```
|
@ -1,17 +1,27 @@
|
||||
# Reference
|
||||
|
||||
```namespaces
|
||||
basic.showString("Hello!");
|
||||
input.onButtonPressed(Button.A, () => {});
|
||||
for (let i = 0;i<5;++i) {}
|
||||
if (true){}
|
||||
let x = 0;
|
||||
Math.random(5);
|
||||
led.plot(0,0);
|
||||
radio.sendNumber(0);
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Whole));
|
||||
game.createSprite(2,2);
|
||||
basic.showNumber(0);
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
|
||||
});
|
||||
led.plot(0, 0);
|
||||
music.playTone(0, 0);
|
||||
game.addScore(1);
|
||||
images.createImage(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`);
|
||||
pins.digitalReadPin(DigitalPin.P0);
|
||||
serial.writeLine("Hello!");
|
||||
control.inBackground(() => {});
|
||||
serial.writeValue(x, 0);
|
||||
control.inBackground(() => {
|
||||
|
||||
});
|
||||
```
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
Provides access to basic micro:bit functionality.
|
||||
|
||||
|
||||
```cards
|
||||
basic.showNumber(0);
|
||||
basic.showLeds(`
|
||||
|
@ -27,5 +27,5 @@ basic.clearScreen()
|
||||
|
||||
### See also
|
||||
|
||||
[set brightness](/reference/led/set-brightness), [unplot](/reference/led/unplot), [plot](/reference/led/plot), [Image](/reference/image/image), [clear](/reference/basic/clear-screen)
|
||||
[set brightness](/reference/led/set-brightness), [unplot](/reference/led/unplot), [plot](/reference/led/plot), [Image](/reference/images/image), [clear](/reference/basic/clear-screen)
|
||||
|
||||
|
@ -57,9 +57,9 @@ input.onButtonPressed(Button.A, () => {
|
||||
|
||||
### Lessons
|
||||
|
||||
[blink](/lessons/blink), [bounce-image](/lessons/bounce-image), [snowflake-fall](/lessons/snowflake-fall), [flashing-heart](/lessons/flashing-heart)
|
||||
[blink](/lessons/blink), [snowflake-fall](/lessons/snowflake-fall), [flashing-heart](/lessons/flashing-heart)
|
||||
|
||||
### See also
|
||||
|
||||
[while](/js/while), [on button pressed](/reference/input/on-button-pressed), [in background](/reference/control/in-background)
|
||||
[while](/reference/loops/while), [on button pressed](/reference/input/on-button-pressed), [in background](/reference/control/in-background)
|
||||
|
||||
|
@ -27,5 +27,5 @@ for (let i = 0; i < 5; i++) {
|
||||
|
||||
### See also
|
||||
|
||||
[while](/js/while), [running time](/reference/input/running-time), [for](/reference/loops/for)
|
||||
[while](/reference/loops/while), [running time](/reference/input/running-time), [for](/reference/loops/for)
|
||||
|
||||
|
@ -57,5 +57,5 @@ Use [forever](/reference/basic/forever) to continually repeat an animation
|
||||
|
||||
### Lessons
|
||||
|
||||
[smiley](/lessons/smiley), [bounce image](/lessons/bounce-image), [snowflake fall](/lessons/snowflake-fall), [rotation animation](/lessons/rotation-animation)
|
||||
[smiley](/lessons/smiley), [snowflake fall](/lessons/snowflake-fall), [rotation animation](/lessons/rotation-animation)
|
||||
|
||||
|
@ -41,5 +41,5 @@ In JavaScript, the led off is represented by a `.` and the led on by a `#` chara
|
||||
|
||||
### See also
|
||||
|
||||
[plot leds](/reference/led/plot-leds), [show animation](/reference/led/show-animation)
|
||||
[plot leds](/reference/led/plot-leds), [show animation](/reference/basic/show-animation)
|
||||
|
||||
|
@ -48,5 +48,5 @@ for (let i = 0; i < 5; i++) {
|
||||
|
||||
### See also
|
||||
|
||||
[show string](/reference/basic/show-string), [show animation](/reference/basic/show-animation), [Number](/reference/types/number), [math library](/js/math)
|
||||
[show string](/reference/basic/show-string), [show animation](/reference/basic/show-animation), [Number](/reference/types/number), [math library](/reference/math)
|
||||
|
||||
|
@ -33,9 +33,9 @@ basic.showString(s)
|
||||
|
||||
### Lessons
|
||||
|
||||
[answering machine](/lessons/answering-machine), [rock paper scissors](/lessons/rock-paper-scissors), [love meter](/lessons/love-meter), [digital pet](/lessons/digital-pet)
|
||||
[answering machine](/lessons/answering-machine), [rock paper scissors](/lessons/rock-paper-scissors), [love meter](/lessons/love-meter)
|
||||
|
||||
### See also
|
||||
|
||||
[String](/reference/types/string), [string functions](/reference/types/string-functions), [show number](/reference/basic/show-number), [show animation](/reference/basic/show-animation)
|
||||
[String](/reference/types/string), [show number](/reference/basic/show-number), [show animation](/reference/basic/show-animation)
|
||||
|
||||
|
@ -1,38 +0,0 @@
|
||||
# Comment
|
||||
|
||||
A note in code.
|
||||
|
||||
### @parent blocks/statement
|
||||
|
||||
A comment is a line of code that contains text, usually an explanation or a note. All comments are ignored during script execution.
|
||||
|
||||
### Block
|
||||
|
||||
Right click on any block and add a comment
|
||||
|
||||
### ~hint
|
||||
|
||||
To find out how to insert comments using the Blocks editor, see [the Blocks editor](/blocks/editor).
|
||||
|
||||
### ~
|
||||
|
||||
### Sample code with comments
|
||||
|
||||

|
||||
|
||||
### Commenting out code
|
||||
|
||||
During the debugging process, you may want to comment out a section of your code so that it doesn't run.
|
||||
|
||||
To comment out a block of code:
|
||||
|
||||
1. Right click on any block of code that you want to comment out.
|
||||
|
||||
1. Select add comment
|
||||
|
||||
When you want to uncomment your code, right click the on the comment, and then click delete block.
|
||||
|
||||
### See also
|
||||
|
||||
[Block editor](/blocks/editor)
|
||||
|
@ -1,7 +1,6 @@
|
||||
# Control
|
||||
|
||||
|
||||
|
||||
Runtime and event utilities.
|
||||
|
||||
```cards
|
||||
control.inBackground(() => {
|
||||
|
@ -8,14 +8,9 @@ The functions in the ``devices`` namespace allow the BBC micro:bit to communicat
|
||||
|
||||
The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device.
|
||||
|
||||
### Block Editor
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
|
||||
```
|
||||
export function onGamepadButton(name: string, body:td.Action)
|
||||
```sig
|
||||
devices.onGamepadButton(MesDpadButtonInfo.ADown, () => {})
|
||||
```
|
||||
|
||||
### Parameters
|
||||
@ -24,5 +19,4 @@ export function onGamepadButton(name: string, body:td.Action)
|
||||
|
||||
### See Also
|
||||
|
||||
[tell remote control to](/reference/devices/tell-remote-control-to), [raise alert to](/reference/devices/raise-alert-to), [on notified](/reference/devices/on-notified), [signal strength](/reference/devices/signal-strength), [on signal strength changed](/reference/devices/on-signal-strength-changed)
|
||||
|
||||
[tell remote control to](/reference/devices/tell-remote-control-to), [raise alert to](/reference/devices/raise-alert-to), [signal strength](/reference/devices/signal-strength), [on signal strength changed](/reference/devices/on-signal-strength-changed)
|
||||
|
@ -10,14 +10,8 @@ The functions in the ``devices`` namespace allow the BBC micro:bit to communicat
|
||||
|
||||
The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device.
|
||||
|
||||
### Block Editor
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
|
||||
```
|
||||
export function onSignalStrengthChanged(body:td.Action)
|
||||
```sig
|
||||
devices.onSignalStrengthChanged(() => {})
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
@ -4,19 +4,14 @@ The raise alert to function.
|
||||
|
||||
Raise an alert on a remote device.
|
||||
|
||||
##
|
||||
## Bluetooth required
|
||||
|
||||
The functions in the ``devices`` namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart).
|
||||
|
||||
The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device.
|
||||
|
||||
### KindScript
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
|
||||
```
|
||||
```sig
|
||||
export function raiseAlertTo(event: string)
|
||||
```
|
||||
|
||||
|
@ -12,14 +12,8 @@ This API does not contain any form of encryption, authentication or authorizatio
|
||||
|
||||
For serious applications, BLE should be considered a substantially more secure alternative.
|
||||
|
||||
### Block Editor
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
|
||||
```
|
||||
export function receiveNumber() : number
|
||||
```sig
|
||||
radio.receiveNumber();
|
||||
```
|
||||
|
||||
### Returns
|
||||
|
@ -4,20 +4,14 @@ The `signal strength` function.
|
||||
|
||||
Returns the signal strength reported by the paired device from ``0`` (no signal) to ``4`` (full strength).
|
||||
|
||||
## Bluetooth required
|
||||
## Important Security Consideration
|
||||
|
||||
The functions in the ``devices`` namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart).
|
||||
|
||||
The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device.
|
||||
|
||||
### Block Editor
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
|
||||
```
|
||||
export function signalStrength() : number
|
||||
devices.signalStrength() : number
|
||||
```
|
||||
|
||||
### Returns
|
||||
|
@ -14,7 +14,7 @@ The set of supported events will depend on the remote device and the BBC micro:b
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
export function tellCameraTo(event: string)
|
||||
|
@ -10,7 +10,7 @@ The functions in the antenna namespace allow the BBC micro:bit to communicate wi
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
export function tellMicrophoneTo(event: string)
|
||||
@ -37,13 +37,13 @@ export function tellMicrophoneTo(event: string)
|
||||
To tell the connected device to start recording audio
|
||||
|
||||
```
|
||||
antenna.tellMicrophoneTo("start capture")
|
||||
devices.tellMicrophoneTo("start capture")
|
||||
```
|
||||
|
||||
To tell the connected device to stop recording audio
|
||||
|
||||
```
|
||||
antenna.tellMicrophoneTo("stop capture")
|
||||
devices.tellMicrophoneTo("stop capture")
|
||||
```
|
||||
|
||||
### Other show functions
|
||||
@ -54,5 +54,5 @@ antenna.tellMicrophoneTo("stop capture")
|
||||
|
||||
### See also
|
||||
|
||||
[Antenna](/js/antenna)
|
||||
[Devices](/reference/devices)
|
||||
|
||||
|
@ -14,7 +14,7 @@ The set of supported events will depend on the remote device and the BBC micro:b
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
export function tellRemoteControlTo(event: string)
|
||||
|
59
docs/reference/event-handler.md
Normal file
59
docs/reference/event-handler.md
Normal file
@ -0,0 +1,59 @@
|
||||
# event handler
|
||||
|
||||
Event handlers - how they work.
|
||||
|
||||
An event handler is code that is associated with a particular event, such as "button A pressed". You create (or register) the association between an event and an event handler by calling a function named "on <event>". After registering an event handler with an event, then whenever that event occurs, the event handler code executes.
|
||||
|
||||
### Registering an event handler
|
||||
|
||||
Functions named "on <event>" create an association between an event and the event handler code. For example, the following code registers the event handler (the code between the `do` and `end` keywords) with the event of a press of button A:
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("hello", 150)
|
||||
})
|
||||
```
|
||||
|
||||
After this code executes, then whenever button A is pressed in the future, the string "hello" will be printed.
|
||||
|
||||
### Event handlers are active for the entire program execution
|
||||
|
||||
Once you have registered an event handler for an event, like above, that event handler is active for the rest of the program execution. If you want to stop the string "hello" from printing each time button A is pressed then you need to arrange for the following code to execute:
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
})
|
||||
```
|
||||
|
||||
The above code associated an event handler that does nothing with the event of a press of button A.
|
||||
|
||||
### There is only one event handler per event
|
||||
|
||||
The above example also illustrates that there is only one event handler for each event. What is the result of the following code?
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("hello", 150)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("goodbye", 150)
|
||||
})
|
||||
```
|
||||
|
||||
The answer is that whenever button A is pressed, the string "goodbye" will be printed. If you want both the strings "hello" and "goodbye" to be printed, you need to write the code like this:
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("hello", 150)
|
||||
basic.showString("goodbye", 150)
|
||||
})
|
||||
```
|
||||
|
||||
### To learn more
|
||||
|
||||
To learn more about how the BBC micro:bit queues up and schedules event handlers, see [the BBC micro:bit - a reactive system](/device/reactive)
|
||||
|
||||
### see also
|
||||
|
||||
[on button pressed](/reference/input/on-button-pressed), [on pin up](/reference/input/on-pin-pressed), [on shake](/reference/input/on-gesture)
|
||||
|
@ -1,7 +1,6 @@
|
||||
# Game
|
||||
|
||||
|
||||
|
||||
A single-LED sprite game engine
|
||||
|
||||
```cards
|
||||
game.addScore(1);
|
||||
|
@ -1,20 +1,8 @@
|
||||
# Change Score By
|
||||
|
||||
The game library
|
||||
|
||||
The game library supports simple single-player time-based games. The player will ** add points to score**.
|
||||
|
||||
## Block Editor
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible and the score will display on the screen.
|
||||
|
||||

|
||||
|
||||
## KindScript
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
|
||||
|
||||
```
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
@ -39,5 +27,5 @@ export function score() : number
|
||||
|
||||
### Lessons
|
||||
|
||||
[bop it](/lessons/bop-it) | [game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter)
|
||||
[game of chance](/lessons/game-of-chance), [game counter](/lessons/game-counter)
|
||||
|
||||
|
@ -1,16 +1,12 @@
|
||||
# Change
|
||||
|
||||
The game library
|
||||
|
||||
### Change
|
||||
|
||||
Sprite will change the x position by this number
|
||||
|
||||
## Block Editor
|
||||
### Block Editor
|
||||
|
||||

|
||||
|
||||
## KindScript
|
||||
### JavaScript
|
||||
|
||||
Sprite will change the x position by this number
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
The clear function for images.
|
||||
|
||||
Turn off all the pixels in an [Image](/reference/image/image).
|
||||
Turn off all the pixels in an [Image](/reference/images/image).
|
||||
|
||||
### KindScript
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
export function clear(img: micro_bit.Image)
|
||||
@ -35,5 +35,5 @@ input.onButtonPressed(Button.A, () => {
|
||||
|
||||
### See also
|
||||
|
||||
[Image](/reference/image/image), [show animation](/reference/basic/show-animation), [show image](/reference/images/show-image), [scroll image](/reference/images/scroll-image), [create image](/reference/images/create-image)
|
||||
[Image](/reference/images/image), [show animation](/reference/basic/show-animation), [show image](/reference/images/show-image), [scroll image](/reference/images/scroll-image), [create image](/reference/images/create-image)
|
||||
|
||||
|
@ -55,5 +55,5 @@ export function startCountdown(ms: number)
|
||||
|
||||
### Lessons
|
||||
|
||||
[bop it](/lessons/bop-it) | [game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter)
|
||||
[game of chance](/lessons/game-of-chance), [game counter](/lessons/game-counter)
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
# Images
|
||||
|
||||
|
||||
|
||||
Creation, manipulation and display of LED images.
|
||||
|
||||
```cards
|
||||
images.createImage(`
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Create Image
|
||||
|
||||
Create an [Image](/reference/image/image) to show on the [LED screen](/device/screen).
|
||||
Create an [Image](/reference/images/image) to show on the [LED screen](/device/screen).
|
||||
|
||||
```sig
|
||||
images.createImage(`
|
||||
@ -35,5 +35,5 @@ input.onGesture(Gesture.Shake, () => {
|
||||
|
||||
### See also
|
||||
|
||||
[show animation](/reference/basic/show-animation), [image](/reference/image/image), [show image](/reference/image/show-image), [scroll image](/reference/image/scroll-image)
|
||||
[show animation](/reference/basic/show-animation), [image](/reference/images/image), [show image](/reference/image/show-image), [scroll image](/reference/image/scroll-image)
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
The pixel function.
|
||||
|
||||
Get the state of a pixel in an [Image](/reference/image/image).
|
||||
Get the state of a pixel in an [Image](/reference/images/image).
|
||||
|
||||
### KindScript
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
export function pixel(_this: micro_bit.Image, x: number, y: number) : boolean
|
||||
@ -12,8 +12,8 @@ export function pixel(_this: micro_bit.Image, x: number, y: number) : boolean
|
||||
|
||||
### Parameters
|
||||
|
||||
* x - [Number](/reference/types/number); the *x coordinate* or horizontal position of a pixel in an [image](/reference/image/image)
|
||||
* y - [Number](/reference/types/number); the *y coordinate* or vertical position of a pixel in an [image](/reference/image/image)
|
||||
* x - [Number](/reference/types/number); the *x coordinate* or horizontal position of a pixel in an [image](/reference/images/image)
|
||||
* y - [Number](/reference/types/number); the *y coordinate* or vertical position of a pixel in an [image](/reference/images/image)
|
||||
|
||||
### x, y coordinates?
|
||||
|
||||
@ -47,5 +47,5 @@ let state = img.pixel(0, 0)
|
||||
|
||||
### See also
|
||||
|
||||
[set pixel](/reference/images/set-pixel), [show image](/reference/images/show-image), [image](/reference/image/image), [create image](/reference/images/create-image), [scroll image](/reference/images/scroll-image)
|
||||
[set pixel](/reference/images/set-pixel), [show image](/reference/images/show-image), [image](/reference/images/image), [create image](/reference/images/create-image), [scroll image](/reference/images/scroll-image)
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
The plot frame function.
|
||||
|
||||
Display an [Image](/reference/image/image) on the BBC micro:bit's [LED screen](/device/screen)
|
||||
Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](/device/screen)
|
||||
|
||||
### KindScript
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
export function plotFrame(_this: micro_bit.Image, index: number)
|
||||
@ -37,5 +37,5 @@ img.plotFrame(1)
|
||||
|
||||
### See also
|
||||
|
||||
[create image](/reference/images/create-image), [show animation](/reference/basic/show-animation), [image](/reference/image/image), [show image](/reference/images/show-image), [scroll image](/reference/images/scroll-image)
|
||||
[create image](/reference/images/create-image), [show animation](/reference/basic/show-animation), [image](/reference/images/image), [show image](/reference/images/show-image), [scroll image](/reference/images/scroll-image)
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
The plot image function.
|
||||
|
||||
Display an [Image](/reference/image/image) on the BBC micro:bit's [LED screen](/device/screen)
|
||||
Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](/device/screen)
|
||||
|
||||
### KindScript
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
export function plotImage(_this: micro_bit.Image, xOffset: number)
|
||||
@ -37,5 +37,5 @@ img.plotImage(0)
|
||||
|
||||
### See also
|
||||
|
||||
[create image](/reference/images/create-image), [show animation](/reference/basic/show-animation), [image](/reference/image/image), [show image](/reference/images/show-image), [scroll image](/reference/images/scroll-image)
|
||||
[create image](/reference/images/create-image), [show animation](/reference/basic/show-animation), [image](/reference/images/image), [show image](/reference/images/show-image), [scroll image](/reference/images/scroll-image)
|
||||
|
||||
|
@ -2,13 +2,13 @@
|
||||
|
||||
The scroll image function.
|
||||
|
||||
Scrolls the frames within an [Image](/reference/image/image) on the [LED screen](/device/screen).
|
||||
Scrolls the frames within an [Image](/reference/images/image) on the [LED screen](/device/screen).
|
||||
|
||||
### Block Editor
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
export function scrollImage(_this: micro_bit.Image, xOffsetPerStep: number, interval: number)
|
||||
@ -69,5 +69,5 @@ img.scrollImage(5, 1000)
|
||||
|
||||
### See also
|
||||
|
||||
[show image](/reference/images/show-image), [image](/reference/image/image), [create image](/reference/images/create-image), [show animation](/reference/basic/show-animation)
|
||||
[show image](/reference/images/show-image), [image](/reference/images/image), [create image](/reference/images/create-image), [show animation](/reference/basic/show-animation)
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
The set pixel function. #set pixel.
|
||||
|
||||
Set the on/off state of pixel in an [Image](/reference/image/image).
|
||||
Set the on/off state of pixel in an [Image](/reference/images/image).
|
||||
|
||||
### KindScript
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
export function setPixel(_this: micro_bit.Image, x: number, y: number, value: boolean)
|
||||
@ -12,8 +12,8 @@ export function setPixel(_this: micro_bit.Image, x: number, y: number, value: bo
|
||||
|
||||
### Parameters
|
||||
|
||||
* x - [Number](/reference/types/number); the *x coordinate* or horizontal position of a pixel in an [image](/reference/image/image)
|
||||
* x - [Number](/reference/types/number); the *y coordinate* or vertical position of a pixel in an [image](/reference/image/image)
|
||||
* x - [Number](/reference/types/number); the *x coordinate* or horizontal position of a pixel in an [image](/reference/images/image)
|
||||
* x - [Number](/reference/types/number); the *y coordinate* or vertical position of a pixel in an [image](/reference/images/image)
|
||||
* value -[Boolean](/reference/types/boolean); the on/off state of a pixel; `true` for on, `false` for off
|
||||
|
||||
### x, y coordinates?
|
||||
@ -38,5 +38,5 @@ img.showImage(0)
|
||||
|
||||
### See also
|
||||
|
||||
[pixel](/reference/images/pixel), [show image](/reference/images/show-image), [image](/reference/image/image), [create image](/reference/images/create-image), [scroll image](/reference/images/scroll-image)
|
||||
[pixel](/reference/images/pixel), [show image](/reference/images/show-image), [image](/reference/images/image), [create image](/reference/images/create-image), [scroll image](/reference/images/scroll-image)
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user