Compare commits
43 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,6 +6,7 @@ temp
|
||||
projects
|
||||
win10/app/bin
|
||||
win10/app/bld
|
||||
win10/*.opendb
|
||||
|
||||
*.user
|
||||
*.sw?
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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!
|
||||
|
||||
|
@ -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)
|
||||
|
@ -26,10 +26,10 @@ Learn how to create a catch the egg game game with **plot**, `led->plot` , **unp
|
||||
* **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)
|
||||
* **math minimum number** : [read more...](/reference/math)
|
||||
* **math maximum number** : [read more...](/reference/math)
|
||||
* **math random number** : [read more...](/reference/math)
|
||||
* **math modulus** : [read more...](/reference/math)
|
||||
* **show number** : [read more...](/reference/basic/show-number)
|
||||
* **pause** : [read more...](/reference/basic/pause)
|
||||
|
||||
|
@ -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!
|
||||
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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!
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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!
|
||||
|
||||
|
@ -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!
|
||||
|
||||
|
@ -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!
|
||||
|
||||
|
@ -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)
|
||||
|
||||
### ~
|
||||
|
@ -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)
|
||||
|
@ -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,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,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)
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
The show 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 showFrame(img: micro_bit.Image, frame: number)
|
||||
@ -37,5 +37,5 @@ img.showFrame(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,13 +2,7 @@
|
||||
|
||||
The show image function.
|
||||
|
||||
Show an [Image](/reference/image/image) on the [LED screen](/device/screen), followed by a 400ms pause.
|
||||
|
||||
### Block Editor
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
Show an [Image](/reference/images/image) on the [LED screen](/device/screen), followed by a 400ms pause.
|
||||
|
||||
```
|
||||
export function showImage(_this: micro_bit.Image, xOffset: number)
|
||||
@ -20,7 +14,7 @@ export function showImage(_this: micro_bit.Image, xOffset: number)
|
||||
|
||||
### Create image and show image
|
||||
|
||||
Use the [image editor](/reference/image/image) to create images using the [create image](/reference/image/create-image) function, and then use `show image` like this:
|
||||
Use the [image editor](/reference/images/image) to create images using the [create image](/reference/images/create-image) function, and then use `show image` like this:
|
||||
|
||||
```
|
||||
let img = images.createImage(`
|
||||
@ -57,5 +51,5 @@ for (let i = 0; i < 5; i++) {
|
||||
|
||||
### See also
|
||||
|
||||
[show animation](/reference/basic/show-animation), [image](/reference/image/image), [create image](/reference/images/create-image), [scroll image](/reference/images/scroll-image)
|
||||
[show animation](/reference/basic/show-animation), [image](/reference/images/image), [create image](/reference/images/create-image), [scroll image](/reference/images/scroll-image)
|
||||
|
||||
|
@ -2,12 +2,10 @@
|
||||
|
||||
The width function.
|
||||
|
||||
Get the width of an [Image](/reference/image/image) in columns.
|
||||
Get the width of an [Image](/reference/images/image) in columns.
|
||||
|
||||
### KindScript
|
||||
|
||||
```
|
||||
export function width(_this: micro_bit.Image) : number
|
||||
```sig
|
||||
images.createImage().width();
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
@ -45,5 +45,5 @@ basic.forever(() => {
|
||||
|
||||
### See also
|
||||
|
||||
[compass-heading](/input/compass-heading), [lightlevel](/input/lightlevel)
|
||||
[compass-heading](/reference/input/compass-heading), [lightlevel](/reference/input/lightlevel)
|
||||
|
||||
|
@ -37,5 +37,5 @@ basic.forever(() => {
|
||||
|
||||
### See also
|
||||
|
||||
[on button pressed](/input/on-button-pressed), [if](/reference/logic/if), [forever](/basic/forever)
|
||||
[on button pressed](/reference/input/on-button-pressed), [if](/reference/logic/if), [forever](/reference/basic/forever)
|
||||
|
||||
|
@ -26,5 +26,5 @@ basic.forever(() => {
|
||||
|
||||
### See also
|
||||
|
||||
[acceleration](/reference/input/acceleration), [compass-heading](/input/compass-heading)
|
||||
[acceleration](/reference/input/acceleration), [compass-heading](/reference/input/compass-heading)
|
||||
|
||||
|
@ -28,5 +28,5 @@ basic.forever(() => {
|
||||
|
||||
### See also
|
||||
|
||||
[compass heading](/input/compass-heading)
|
||||
[compass heading](/reference/input/compass-heading)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# On Button Pressed
|
||||
|
||||
Register an [event handler](/reference/event-handler) that will execute whenever an input button (A, B, or A and B together) is pressed during program execution. When [running code](/js/simulator) with this function in a web browser, click an on-screen input button - labelled A or B.
|
||||
Register an [event handler](/reference/event-handler) that will execute whenever an input button (A, B, or A and B together) is pressed during program execution. When [running code](/device/simulator) with this function in a web browser, click an on-screen input button - labelled A or B.
|
||||
|
||||
```sig
|
||||
input.onButtonPressed(Button.A, () => {})
|
||||
|
@ -28,5 +28,5 @@ input.onPinPressed(TouchPin.P0, () => {
|
||||
|
||||
### See also
|
||||
|
||||
[BBC micro:bit pins](/device/pins), [pin is pressed](/input/pin-is-pressed), [analog read pin](/pins/analog-read-pin), [analog write pin](/pins/analog-write-pin), [digital read pin](/pins/digital-read-pin), [digital write pin](/pins/digital-write-pin)
|
||||
[BBC micro:bit pins](/device/pins), [pin is pressed](/reference/input/pin-is-pressed), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin)
|
||||
|
||||
|
@ -32,5 +32,5 @@ basic.forever(() => {
|
||||
|
||||
### See also
|
||||
|
||||
[BBC micro:bit pins](/device/pins), [on pin pressed](/input/on-pin-pressed), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin)
|
||||
[BBC micro:bit pins](/device/pins), [on pin pressed](/reference/input/on-pin-pressed), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin)
|
||||
|
||||
|
@ -1,81 +0,0 @@
|
||||
# Antenna Library
|
||||
|
||||
The events library #docs
|
||||
|
||||
The functions in the ``antenna`` 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.
|
||||
|
||||
### Remote control
|
||||
|
||||
Control the presentation of media content available on a remote device using the `tell remote control to` function
|
||||
|
||||
```
|
||||
export function tellRemoteControlTo(event: string)
|
||||
```
|
||||
|
||||
The remote control specific events include:
|
||||
|
||||
* play
|
||||
* pause
|
||||
* stop
|
||||
* next track
|
||||
* previous track
|
||||
* forward
|
||||
* rewind
|
||||
* volume up
|
||||
* volume down
|
||||
|
||||
### Camera
|
||||
|
||||
Access the photo/video-taking functionality of a remote device using the *camera* function:
|
||||
|
||||
```
|
||||
export function tellCameraTo(event: string)
|
||||
```
|
||||
|
||||
The camera-specific events include:
|
||||
|
||||
* toggle front-rear
|
||||
* launch photo mode
|
||||
* take photo
|
||||
* stop photo mode
|
||||
* launch video mode
|
||||
* start video capture
|
||||
* stop video capture
|
||||
* stop video mode
|
||||
|
||||
### Alert
|
||||
|
||||
Raise an alert on a remote device using the `raise alert to` function
|
||||
|
||||
```
|
||||
export function raiseAlertTo(event: string)
|
||||
```
|
||||
|
||||
The set of alerting-specific events include:
|
||||
|
||||
* display toast
|
||||
* vibrate
|
||||
* play sound
|
||||
* play ringtone
|
||||
* find my phone
|
||||
* alarm 1
|
||||
* alarm 2
|
||||
* alarm 3
|
||||
* alarm 4
|
||||
* alarm 5
|
||||
* alarm 6
|
||||
|
||||
### Microphone
|
||||
|
||||
Access the audio recording capabilities of the device using the `tell microphone to` function
|
||||
|
||||
```
|
||||
export function tellMicrophoneTo(event: string)
|
||||
```
|
||||
|
||||
The set of audio recorder events include:
|
||||
|
||||
* launch
|
||||
* start capture
|
||||
* end capture
|
||||
* stop
|
@ -1,8 +1,6 @@
|
||||
# Plot LEDs
|
||||
|
||||
Display an [Image](/reference/image/image) on the BBC micro:bit's [LED screen](/device/screen). NOTE: `basic -> plot image` has been replaced by `basic -> show leds`.
|
||||
|
||||
### KindScript syntax
|
||||
Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](/device/screen). NOTE: `basic -> plot image` has been replaced by `basic -> show leds`.
|
||||
|
||||
```sig
|
||||
basic.plotLeds(`
|
||||
@ -36,5 +34,5 @@ basic.plotLeds(`
|
||||
|
||||
### See also
|
||||
|
||||
[show animation](/reference/basic/show-animation), [image](/reference/image/image), [show image](/reference/images/show-image), [scroll image](/reference/images/scroll-image)
|
||||
[show animation](/reference/basic/show-animation), [image](/reference/images/image), [show image](/reference/images/show-image), [scroll image](/reference/images/scroll-image)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Screenshot
|
||||
|
||||
Make an [Image](/reference/image/image) out of the current state of the [LED screen](/device/screen).
|
||||
Make an [Image](/reference/images/image) out of the current state of the [LED screen](/device/screen).
|
||||
|
||||
```sig
|
||||
led.screenshot();
|
||||
@ -12,7 +12,7 @@ led.screenshot();
|
||||
|
||||
### Returns
|
||||
|
||||
* an [Image](/reference/image/image) of what is currently visible on the [LED screen](/device/screen)
|
||||
* an [Image](/reference/images/image) of what is currently visible on the [LED screen](/device/screen)
|
||||
|
||||
### See also
|
||||
|
||||
|
@ -24,5 +24,5 @@ for (let k = 0; k < 4; k++) {
|
||||
|
||||
### See also
|
||||
|
||||
[while](/reference/loops/while), [if](/blocks/if)
|
||||
[while](/reference/loops/while), [if](/reference/logic/if)
|
||||
|
||||
|
@ -39,5 +39,5 @@ The following example uses a while loop to make a diagonal line on the LED scree
|
||||
|
||||
### See also
|
||||
|
||||
[on button pressed](/reference/input/on-button-pressed), [for](/reference/loops/for), [if](/blocks/if), [forever](/reference/basic/forever)
|
||||
[on button pressed](/reference/input/on-button-pressed), [for](/reference/loops/for), [if](/reference/logic/if), [forever](/reference/basic/forever)
|
||||
|
||||
|
@ -2,17 +2,9 @@
|
||||
|
||||
The micro:bit pins.
|
||||
|
||||
## We listened to your feedback!
|
||||
|
||||
Following the feedback from teachers, the following improvements were made:
|
||||
|
||||
* compile without signing in
|
||||
* compile offline
|
||||
* save and load code using files
|
||||
|
||||
## How to work offline
|
||||
|
||||
If you have loaded the web app at some time in the past (by clicking on "my scripts" from the home page), then if you later open the same browser (whether you are online or offline) and type in the URL KINDSCRIPTWEBSITE, you will be able to access all the features of the web app. Note that it is important to end the URL with "/".
|
||||
If you have loaded the web app at some time in the past (by clicking on "my scripts" from the home page), then if you later open the same browser (whether you are online or offline) and type in [https://codemicrobit.com/](https://codemicrobit.com/), you will be able to access all the features of the web app. Note that it is important to end the URL with "/".
|
||||
|
||||
## Save and load code using files
|
||||
|
||||
@ -24,7 +16,7 @@ The micro:bit automatically saves and synchronises scripts for signed-in users t
|
||||
|
||||
## The new in-browser compiler
|
||||
|
||||
The compilation from a script to ARM machine code is now done entirely in the browser (read the [in depth story](https://www.touchdevelop.com/docs/touch-develop-in-208-bits) about building the compiler). The new compiler is used by the Block Editor, Touch Develop and Code Kingdoms to create a .hex file solely within the confines of your web browser (no Internet connection is needed). The micro:bit compilation process (see page 10 in the [Quick Start Guide](/js/quick-start)) has been updated below to reflect the new compiler architecture, as shown below:
|
||||
The compilation from a script to ARM machine code is now done entirely in the browser (read the [in depth story](https://www.touchdevelop.com/docs/touch-develop-in-208-bits) about building the compiler). The new compiler is used by the Block Editor, Touch Develop and Code Kingdoms to create a .hex file solely within the confines of your web browser (no Internet connection is needed). The micro:bit compilation process is shown below:
|
||||
|
||||

|
||||
|
||||
|
@ -8,8 +8,8 @@ For example, the [plot](/reference/led/plot) function has two parameters:
|
||||
|
||||
### syntax
|
||||
|
||||
```
|
||||
export function plot(x: number, y: number)
|
||||
```sig
|
||||
led.plot(0,0)
|
||||
```
|
||||
|
||||
### parameters
|
||||
@ -21,7 +21,7 @@ export function plot(x: number, y: number)
|
||||
|
||||
here's an example of code with an out of bounds parameter (the *x* and *y* parameters are outside the expected range of 0-4):
|
||||
|
||||
```
|
||||
```blocks
|
||||
led.plot(9, -21)
|
||||
```
|
||||
|
||||
@ -33,11 +33,8 @@ Typically, when a parameter supplied to a function is out of bounds that functio
|
||||
|
||||
If you call the `point` function with an out of bounds parameter, the function returns `false`:
|
||||
|
||||
```
|
||||
```blocks
|
||||
let on = led.point(5, -5)
|
||||
```
|
||||
|
||||
### see also
|
||||
|
||||
For more information on the out-of-bounds behavior of a function, see the documentation for that [function](/js/contents).
|
||||
|
||||
|
@ -31,5 +31,5 @@ radio.onDataReceived(() => {
|
||||
|
||||
### See also
|
||||
|
||||
[receive number](/radio/receive-number), [send number](/radio/send-number), [set group](/reference/radio/set-group)
|
||||
[receive number](/reference/radio/receive-number), [send number](/reference/radio/send-number), [set group](/reference/radio/set-group)
|
||||
|
||||
|
@ -30,5 +30,5 @@ radio.onDataReceived(() => {
|
||||
|
||||
### See also
|
||||
|
||||
[receive number](/input/receive-number), [on data received](/reference/radio/on-data-received)
|
||||
[receive number](/reference/input/receive-number), [on data received](/reference/radio/on-data-received)
|
||||
|
||||
|
@ -30,5 +30,5 @@ input.onButtonPressed(Button.A, () => {
|
||||
|
||||
### See also
|
||||
|
||||
[receive number](/input/receive-number), [on data received](/reference/radio/on-data-received)
|
||||
[receive number](/reference/radio/receive-number), [on data received](/reference/radio/on-data-received)
|
||||
|
||||
|
@ -18,7 +18,7 @@ radio.setGroup(1)
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``id`` -- a [number](/number) between ``0`` and ``255``.
|
||||
* ``id`` -- a [number](/reference/types/number) between ``0`` and ``255``.
|
||||
|
||||
### Example
|
||||
|
||||
@ -30,5 +30,5 @@ radio.setGroup(128)
|
||||
|
||||
### See also
|
||||
|
||||
[receive number](/radio/receive-number), [send number](/radio/send-number), [on data received](/radio/on-data-received)
|
||||
[receive number](/reference/radio/receive-number), [send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)
|
||||
|
||||
|
8
docs/reference/serial.md
Normal file
8
docs/reference/serial.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Serial
|
||||
|
||||
[Serial communication](/device/serial) between the BBC micro:bit and another computer.
|
||||
|
||||
```cards
|
||||
serial.writeLine("");
|
||||
serial.writeValue("x", 0);
|
||||
```
|
33
docs/reference/serial/write-line.md
Normal file
33
docs/reference/serial/write-line.md
Normal file
@ -0,0 +1,33 @@
|
||||
# Write Line
|
||||
|
||||
Writes a string and a new line character (`\r\n`) to [serial](/device/serial).
|
||||
|
||||
```sig
|
||||
serial.writeLine("");
|
||||
```
|
||||
|
||||
### Example: streaming data
|
||||
|
||||
The following example constantly checks the [compass heading](/reference/input/compass-heading) and sends the direction to serial.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let heading = input.compassHeading()
|
||||
if (heading < 45) {
|
||||
serial.writeLine("N");
|
||||
} else if (heading < 135) {
|
||||
serial.writeLine("E");
|
||||
}
|
||||
else if (heading < 225) {
|
||||
serial.writeLine("S");
|
||||
}
|
||||
else {
|
||||
serial.writeLine("W");
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[serial](/device/serial), [write value](/reference/serial/write-value)
|
||||
|
36
docs/reference/serial/write-value.md
Normal file
36
docs/reference/serial/write-value.md
Normal file
@ -0,0 +1,36 @@
|
||||
# Write Value
|
||||
|
||||
Writes name/value pair and a new line character (`\r\n`) to [serial](/device/serial).
|
||||
|
||||
```sig
|
||||
serial.writeValue("x", 0);
|
||||
```
|
||||
|
||||
### Example: streaming data
|
||||
|
||||
The sample below sends the temperature and light level every 10 seconds.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
serial.writeValue("temp", input.temperature())
|
||||
serial.writeValue("light", input.lightLevel())
|
||||
basic.pause(10000);
|
||||
})
|
||||
```
|
||||
|
||||
### Plot bar graph does serial!
|
||||
|
||||
If you use the `led.plotBarGraph` function, it automatically writes the value to the serial as well.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plotBarGraph(input.lightLevel(), 255)
|
||||
basic.pause(10000);
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
### See also
|
||||
|
||||
[serial](/device/serial), [write line](/reference/serial/write-line)
|
||||
|
@ -32,7 +32,7 @@ The next six blocks represent comparison operators that yield a Boolean value. M
|
||||
42 >= 0;
|
||||
```
|
||||
|
||||
Boolean values and operators are often used with an [if](/blocks/if) or [while](/reference/loops/while) statement to determine which code will execute next. For example:
|
||||
Boolean values and operators are often used with an [if](/reference/logic/if) or [while](/reference/loops/while) statement to determine which code will execute next. For example:
|
||||
|
||||
### Functions that return a Boolean
|
||||
|
||||
@ -104,5 +104,5 @@ See the documentation on [Numbers](/reference/types/number) for more information
|
||||
|
||||
### See also
|
||||
|
||||
[if](/blocks/if), [while](/reference/loops/while), [number](/reference/types/number)
|
||||
[if](/reference/logic/if), [while](/reference/loops/while), [number](/reference/types/number)
|
||||
|
||||
|
@ -20,7 +20,7 @@ The following arithmetic operators work on numbers and return a [Number](/refere
|
||||
* subtraction: `1 - 3 `
|
||||
* multiplication: `3 * 2`
|
||||
* integer division: `7 / 3`
|
||||
* modulo is available through the [math library](/blocks/math)
|
||||
* modulo is available through the [math library](/reference/math)
|
||||
|
||||
### Relational operators
|
||||
|
||||
@ -47,7 +47,7 @@ Some functions return a number, which you can store in a variable. For example t
|
||||
|
||||
### Math functions
|
||||
|
||||
The [math library](/blocks/math) includes math related functions. In the [Block Editor](/blocks/editor), click `math` on the Code Keyboard to see the math functions. For example, the `absolute` function returns the returns the absolute value of input parameter `x`:
|
||||
The [math library](/reference/math) includes math related functions. In the [Block Editor](/blocks/editor), click `math` on the Code Keyboard to see the math functions. For example, the `absolute` function returns the returns the absolute value of input parameter `x`:
|
||||
|
||||

|
||||
|
||||
@ -57,5 +57,5 @@ The [math library](/blocks/math) includes math related functions. In the [Block
|
||||
|
||||
### See also
|
||||
|
||||
[math library](/blocks/math), [var](/reference/variables/var), [Boolean](/reference/types/boolean), [show number](/reference/basic/show-number)
|
||||
[math library](/reference/math), [var](/reference/variables/var), [Boolean](/reference/types/boolean), [show number](/reference/basic/show-number)
|
||||
|
||||
|
@ -28,7 +28,7 @@ let num1 = 42
|
||||
````
|
||||
### Notes
|
||||
|
||||
* You can use the assignment operator with variables of each of the supported [types](/blocks/types).
|
||||
* You can use the assignment operator with variables of each of the supported [types](/reference/types).
|
||||
|
||||
### Lessons
|
||||
|
||||
@ -36,5 +36,5 @@ let num1 = 42
|
||||
|
||||
### See also
|
||||
|
||||
[variable](/reference/variables/var), [types](/blocks/types)
|
||||
[variable](/reference/variables/var), [types](/reference/types)
|
||||
|
||||
|
@ -32,9 +32,9 @@ basic.showNumber(x);
|
||||
|
||||
### Notes
|
||||
|
||||
* You can use the assignment operator with variables of each of the supported [types](/blocks/types).
|
||||
* You can use the assignment operator with variables of each of the supported [types](/reference/types).
|
||||
|
||||
### See also
|
||||
|
||||
[variable](/reference/variables/var), [types](/blocks/types)
|
||||
[variable](/reference/variables/var), [types](/reference/types)
|
||||
|
||||
|
@ -4,7 +4,7 @@ How to define and use local variables.
|
||||
|
||||
### @parent language
|
||||
|
||||
A variable is a place where you can store and retrieve data. Variables have a name, a [type](/blocks/types), and value:
|
||||
A variable is a place where you can store and retrieve data. Variables have a name, a [type](/reference/types), and value:
|
||||
|
||||
* *name* is how you'll refer to the variable
|
||||
* *type* refers to the kind of data a variable can store
|
||||
@ -12,12 +12,15 @@ A variable is a place where you can store and retrieve data. Variables have a na
|
||||
|
||||
### Var statement
|
||||
|
||||
Use the Block Editor variable statement to create a local variable and the [assignment operator](/reference/variables/assign) to store something in the variable.
|
||||
Use the Block Editor variable statement to create a variable
|
||||
and the [assignment operator](/reference/variables/assign)
|
||||
to store something in the variable.
|
||||
|
||||
For example, this code stores the number `2` in the `num1` variable:
|
||||
|
||||

|
||||
For example, this code stores the number `2` in the `x` variable:
|
||||
|
||||
```blocks
|
||||
let x = 2;
|
||||
```
|
||||
Here's how to define a variable in the Block Editor:
|
||||
|
||||
1. Click `variables`.
|
||||
@ -26,57 +29,53 @@ Here's how to define a variable in the Block Editor:
|
||||
|
||||
3. Drag a block type on the right-side of the [assignment operator](/reference/variables/assign) and click the down arrow to change the variable name.
|
||||
|
||||
The resulting code should look something like this:
|
||||
|
||||
// string variable
|
||||
|
||||

|
||||
|
||||
// number variable
|
||||
|
||||

|
||||
|
||||
// boolean variable
|
||||
|
||||

|
||||
|
||||
// image variable
|
||||
|
||||

|
||||
|
||||
See [Image](/blocks/image) for info on creating and using image variables.
|
||||
|
||||
The resulting code should look something like this:
|
||||
|
||||

|
||||
|
||||
A variable is created for the number returned by the [brightness](/reference/led/brightness) function.
|
||||
|
||||
```blocks
|
||||
let b = led.brightness();
|
||||
```
|
||||
|
||||
### Using variables
|
||||
|
||||
Once you've defined a variable, just use the variable's name whenever you need what's stored in the variable. For example, the following code shows the value stored in `counter` on the LED screen:
|
||||
|
||||

|
||||
```blocks
|
||||
let counter = 1;
|
||||
basic.showNumber(counter);
|
||||
```
|
||||
|
||||
To change the contents of a variable use the assignment operator. The following code sets `counter` to 1 and then increments `counter` by 10:
|
||||
|
||||

|
||||
```blocks
|
||||
let counter = 1;
|
||||
counter = counter + 10;
|
||||
basic.showNumber(counter);
|
||||
```
|
||||
|
||||
### Why use variables?
|
||||
|
||||
Variables help simplify your code. For example, instead of turning on LEDs one by one like this:
|
||||
If you want to remember and modify data, you'll need a variable.
|
||||
A counter is a great example:
|
||||
|
||||

|
||||
|
||||
You can use a variable (`i`) and a [for loop](/reference/loops/for) to plot the same series of points (`i` is incremented by 1, each time the loop repeats):
|
||||
|
||||

|
||||
```blocks
|
||||
let counter = 0;
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
counter = counter + 1;
|
||||
basic.showNumber(counter);
|
||||
});
|
||||
```
|
||||
|
||||
### Local variables
|
||||
|
||||
Local variables exist only within the function or block of code where they're defined. For example:
|
||||
|
||||

|
||||
```blocks
|
||||
// x does NOT exist here.
|
||||
if (led.brightness() > 128) {
|
||||
// x exists here
|
||||
let x = 0;
|
||||
}
|
||||
```
|
||||
|
||||
#### Notes
|
||||
|
||||
@ -88,5 +87,5 @@ Local variables exist only within the function or block of code where they're de
|
||||
|
||||
### See also
|
||||
|
||||
[types](/blocks/types), [assignment operator](/reference/variables/assign)
|
||||
[types](/reference/types), [assignment operator](/reference/variables/assign)
|
||||
|
||||
|
BIN
docs/static/favicon.png
vendored
Normal file
BIN
docs/static/favicon.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
@ -11,9 +11,13 @@
|
||||
"dependencies": {
|
||||
"microbit": "file:../microbit"
|
||||
},
|
||||
"microbit": {
|
||||
"yotta": {
|
||||
"config": {
|
||||
"MICROBIT_BLE_ENABLED": "1"
|
||||
"microbit-dal": {
|
||||
"bluetooth": {
|
||||
"enabled": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"installedVersion": "zakvul"
|
||||
|
@ -12,10 +12,14 @@
|
||||
"dependencies": {
|
||||
"microbit": "file:../microbit"
|
||||
},
|
||||
"microbit": {
|
||||
"yotta": {
|
||||
"config": {
|
||||
"MICROBIT_BLE_ENABLED": "0"
|
||||
"microbit-dal": {
|
||||
"bluetooth": {
|
||||
"enabled": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"installedVersion": "rlfgis"
|
||||
}
|
||||
}
|
@ -13,7 +13,10 @@ namespace radio {
|
||||
|
||||
int radioEnable() {
|
||||
int r = uBit.radio.enable();
|
||||
if (r != MICROBIT_OK) return r;
|
||||
if (r != MICROBIT_OK) {
|
||||
uBit.panic(43);
|
||||
return r;
|
||||
}
|
||||
if (!radioEnabled) {
|
||||
uBit.radio.setGroup(pxt::programHash());
|
||||
radioEnabled = true;
|
||||
|
@ -58,7 +58,7 @@ namespace basic {
|
||||
int l = s.length();
|
||||
if (l == 0) {
|
||||
uBit.display.clear();
|
||||
uBit.sleep(interval * 5);
|
||||
fiber_sleep(interval * 5);
|
||||
} else if (l > 1) {
|
||||
uBit.display.scroll(s, interval);
|
||||
} else {
|
||||
@ -98,7 +98,7 @@ namespace basic {
|
||||
void forever_stub(void *a) {
|
||||
while (true) {
|
||||
runAction0((Action)a);
|
||||
uBit.sleep(20);
|
||||
fiber_sleep(20);
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,6 +123,6 @@ namespace basic {
|
||||
//% async block="pause (ms) %pause"
|
||||
//% blockId=device_pause icon="\uf110"
|
||||
void pause(int ms) {
|
||||
uBit.sleep(ms);
|
||||
fiber_sleep(ms);
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ namespace control {
|
||||
//% weight=30 async help=control/reset
|
||||
//% blockId="control_reset" block="reset"
|
||||
void reset() {
|
||||
uBit.reset();
|
||||
microbit_reset();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -151,7 +151,7 @@ namespace control {
|
||||
* Raises an event in the event bus.
|
||||
*/
|
||||
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source|with value %value=control_event_value"
|
||||
//% blockExternalInputs=1 blockStatement=1
|
||||
//% blockExternalInputs=1
|
||||
void onEvent(int src, int value, Action handler) {
|
||||
registerWithDal(src, value, handler);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "ksbit.h"
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
namespace String_ {
|
||||
//%
|
||||
StringData *charAt(StringData *s, int pos) {
|
||||
@ -127,13 +128,13 @@ namespace Math_ {
|
||||
//%
|
||||
int random(int max) {
|
||||
if (max == INT_MIN)
|
||||
return -uBit.random(INT_MAX);
|
||||
return -microbit_random(INT_MAX);
|
||||
else if (max < 0)
|
||||
return -uBit.random(-max);
|
||||
return -microbit_random(-max);
|
||||
else if (max == 0)
|
||||
return 0;
|
||||
else
|
||||
return uBit.random(max);
|
||||
return microbit_random(max);
|
||||
}
|
||||
|
||||
//%
|
||||
@ -298,6 +299,6 @@ namespace pxtrt {
|
||||
//%
|
||||
void panic(int code)
|
||||
{
|
||||
uBit.panic(code);
|
||||
microbit_panic(code);
|
||||
}
|
||||
}
|
||||
|
9
libs/microbit/dal.d.ts
vendored
9
libs/microbit/dal.d.ts
vendored
@ -2,7 +2,9 @@
|
||||
declare const enum DAL {
|
||||
// built/yt/yotta_modules/microbit-dal/inc//bluetooth/ExternalEvents.h
|
||||
MICROBIT_ID_BLE = 1000,
|
||||
MICROBIT_ID_BLE_UART = 1001,
|
||||
MICROBIT_ID_BLE_UART = 1200,
|
||||
MICROBIT_BLE_EVT_CONNECTED = 1,
|
||||
MICROBIT_BLE_EVT_DISCONNECTED = 2,
|
||||
// built/yt/yotta_modules/microbit-dal/inc//bluetooth/MESEvents.h
|
||||
MES_REMOTE_CONTROL_ID = 1001,
|
||||
MES_REMOTE_CONTROL_EVT_PLAY = 1,
|
||||
@ -294,6 +296,7 @@ declare const enum DAL {
|
||||
// built/yt/yotta_modules/microbit-dal/inc//drivers/MicroBitDisplay.h
|
||||
MICROBIT_DISPLAY_EVT_ANIMATION_COMPLETE = 1,
|
||||
MICROBIT_DISPLAY_EVT_LIGHT_SENSE = 2,
|
||||
MICROBIT_DISPLAY_DEFAULT_AUTOCLEAR = 1,
|
||||
MICROBIT_DISPLAY_SPACING = 1,
|
||||
MICROBIT_DISPLAY_GREYSCALE_BIT_DEPTH = 8,
|
||||
MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS = -255,
|
||||
@ -303,7 +306,8 @@ declare const enum DAL {
|
||||
ANIMATION_MODE_PRINT_TEXT = 3,
|
||||
ANIMATION_MODE_SCROLL_IMAGE = 4,
|
||||
ANIMATION_MODE_ANIMATE_IMAGE = 5,
|
||||
ANIMATION_MODE_PRINT_CHARACTER = 6,
|
||||
ANIMATION_MODE_ANIMATE_IMAGE_WITH_CLEAR = 6,
|
||||
ANIMATION_MODE_PRINT_CHARACTER = 7,
|
||||
DISPLAY_MODE_BLACK_AND_WHITE = 0,
|
||||
DISPLAY_MODE_GREYSCALE = 1,
|
||||
DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE = 2,
|
||||
@ -384,6 +388,7 @@ declare const enum DAL {
|
||||
MICROBIT_THERMOMETER_PERIOD = 1000,
|
||||
MICROBIT_THERMOMETER_EVT_UPDATE = 1,
|
||||
MICROBIT_THERMOMETER_ADDED_TO_IDLE = 2,
|
||||
// built/yt/yotta_modules/microbit-dal/inc//platform/yotta_cfg_mappings.h
|
||||
// built/yt/yotta_modules/microbit-dal/inc//types/ManagedString.h
|
||||
// built/yt/yotta_modules/microbit-dal/inc//types/ManagedType.h
|
||||
// built/yt/yotta_modules/microbit-dal/inc//types/Matrix4.h
|
||||
|
2
libs/microbit/enums.d.ts
vendored
2
libs/microbit/enums.d.ts
vendored
@ -281,5 +281,7 @@ declare namespace serial {
|
||||
Int32BE = 10,
|
||||
// UInt32,
|
||||
}
|
||||
declare namespace storage {
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
||||
|
@ -247,7 +247,7 @@ namespace input {
|
||||
//% help=input/running-time weight=50
|
||||
//% blockId=device_get_running_time block="running time (ms)" icon="\uf017"
|
||||
int runningTime() {
|
||||
return uBit.systemTime();
|
||||
return system_timer_current_time();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,8 +180,9 @@ namespace pins {
|
||||
}
|
||||
|
||||
if (ms > 0) {
|
||||
uBit.sleep(ms);
|
||||
fiber_sleep(ms);
|
||||
pitchPin->setAnalogValue(0);
|
||||
// TODO why do we use wait_ms() here? it's a busy wait I think
|
||||
wait_ms(5);
|
||||
}
|
||||
}
|
||||
|
@ -26,13 +26,18 @@
|
||||
"pins.ts",
|
||||
"serial.cpp",
|
||||
"serial.ts",
|
||||
"buffer.cpp"
|
||||
"buffer.cpp",
|
||||
"storage.cpp"
|
||||
],
|
||||
"public": true,
|
||||
"dependencies": {},
|
||||
"microbit": {
|
||||
"yotta": {
|
||||
"config": {
|
||||
"MESSAGE_BUS_LISTENER_DEFAULT_FLAGS": "MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY"
|
||||
"microbit-dal": {
|
||||
"bluetooth": {
|
||||
"enabled": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ namespace serial {
|
||||
* Prints a line of text to the serial
|
||||
* @param value to send over serial
|
||||
*/
|
||||
//% help=/serial/write-line
|
||||
//% blockId=serial_writeline block="serial|write %text"
|
||||
export function writeLine(text: string): void {
|
||||
writeString(text);
|
||||
@ -26,6 +27,7 @@ namespace serial {
|
||||
* @param value to write
|
||||
*/
|
||||
//% weight=80
|
||||
//% help=/serial/write-value
|
||||
//% blockId=serial_writevalue block="serial|write %name|= %value"
|
||||
export function writeValue(name: string, value: number): void {
|
||||
writeString(name);
|
||||
|
35
libs/microbit/shims.d.ts
vendored
35
libs/microbit/shims.d.ts
vendored
@ -340,7 +340,7 @@ declare namespace control {
|
||||
* Raises an event in the event bus.
|
||||
*/
|
||||
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source|with value %value=control_event_value"
|
||||
//% blockExternalInputs=1 blockStatement=1 shim=control::onEvent
|
||||
//% blockExternalInputs=1 shim=control::onEvent
|
||||
function onEvent(src: number, value: number, handler: () => void): void;
|
||||
}
|
||||
|
||||
@ -585,4 +585,37 @@ declare interface Buffer {
|
||||
write(dstOffset: number, src: Buffer): void;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This allows reading and writing of small blocks of data to FLASH memory.
|
||||
*/
|
||||
//% weight=10 color=#cc6600
|
||||
declare namespace storage {
|
||||
|
||||
/**
|
||||
* Writes the key and buffer pair into FLASH. This operation is rather costly as all the key/value pairs
|
||||
* have to be rewritten as well.
|
||||
*/
|
||||
//% shim=storage::putBuffer
|
||||
function putBuffer(key: string, buffer: Buffer): void;
|
||||
|
||||
/**
|
||||
* Gets the buffer at the given key if any. If no key is available, empty buffer is returned.
|
||||
*/
|
||||
//% shim=storage::getBuffer
|
||||
function getBuffer(key: string): Buffer;
|
||||
|
||||
/**
|
||||
* Removes an entry identified by the key.
|
||||
*/
|
||||
//% shim=storage::remove
|
||||
function remove(key: string): void;
|
||||
|
||||
/**
|
||||
* The number of entries in the key value store
|
||||
*/
|
||||
//% shim=storage::size
|
||||
function size(): number;
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
||||
|
43
libs/microbit/storage.cpp
Normal file
43
libs/microbit/storage.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include "ksbit.h"
|
||||
|
||||
/**
|
||||
* This allows reading and writing of small blocks of data to FLASH memory.
|
||||
*/
|
||||
//% weight=10 color=#cc6600
|
||||
namespace storage {
|
||||
/**
|
||||
* Writes the key and buffer pair into FLASH. This operation is rather costly as all the key/value pairs
|
||||
* have to be rewritten as well.
|
||||
*/
|
||||
//%
|
||||
void putBuffer(StringData* key, Buffer buffer) {
|
||||
uBit.storage.put(ManagedString(key), ManagedBuffer(buffer).getBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the buffer at the given key if any. If no key is available, empty buffer is returned.
|
||||
*/
|
||||
//%
|
||||
Buffer getBuffer(StringData* key) {
|
||||
KeyValuePair* pv = uBit.storage.get(ManagedString(key));
|
||||
if (pv == NULL) return ManagedBuffer().leakData();
|
||||
|
||||
return ManagedBuffer(pv->value, sizeof(pv->value)).leakData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an entry identified by the key.
|
||||
*/
|
||||
//%
|
||||
void remove(StringData * key) {
|
||||
uBit.storage.remove(ManagedString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of entries in the key value store
|
||||
*/
|
||||
//%
|
||||
int size() {
|
||||
return uBit.storage.size();
|
||||
}
|
||||
}
|
@ -18,5 +18,5 @@
|
||||
"dependencies": {
|
||||
"microbit": "file:../microbit"
|
||||
},
|
||||
"installedVersion": "zbhlje"
|
||||
"installedVersion": "fgluxh"
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user