Compare commits

...

43 Commits

Author SHA1 Message Date
4b40585690 0.2.83 2016-04-21 14:26:36 -07:00
dd65efaab6 Bump pxt-core to 0.2.92 2016-04-21 14:26:34 -07:00
890c2566af 0.2.82 2016-04-20 07:13:06 -07:00
cd71fc5d13 Bump pxt-core to 0.2.89 2016-04-20 07:13:04 -07:00
f626dd4bbb 0.2.81 2016-04-19 20:52:09 -07:00
956992e9ab Bump pxt-core to 0.2.88 2016-04-19 20:52:08 -07:00
91ddcef6ce 0.2.80 2016-04-19 16:30:49 -07:00
49fa42473f Bump pxt-core to 0.2.86 2016-04-19 16:30:47 -07:00
564de8863a fix scrollbar 2016-04-19 13:26:00 -07:00
1dd70100d6 Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-04-19 13:25:46 -07:00
a38ff18eaf 0.2.79 2016-04-19 12:58:18 -07:00
d46ef1efca Bump pxt-core to 0.2.83 2016-04-19 12:58:16 -07:00
c54cd21efa Don't go through uBit object if not needed 2016-04-19 11:52:44 -07:00
94f18340ec prevent elastic scroll in simulator 2016-04-19 10:06:36 -07:00
13bdcf762d updated dal definition 2016-04-19 09:43:23 -07:00
6455da6adb 0.2.78 2016-04-18 22:55:03 -07:00
4e88ba4ef2 Bump pxt-core to 0.2.82 2016-04-18 22:55:01 -07:00
0c7d49256d don't use blockStatement anymore 2016-04-18 13:31:05 -07:00
c2883d00ee use registerwithdal in simulator 2016-04-18 10:46:44 -07:00
7da483f258 fixing links 2016-04-18 09:47:34 -07:00
6cbc6a53b2 more missing simulator functions 2016-04-18 09:47:27 -07:00
5e23bc96ca don't expose storage in blocks 2016-04-18 09:21:11 -07:00
4169663a8b fixing broken links 2016-04-18 08:33:09 -07:00
4795c58e97 initial blocks for storage 2016-04-16 07:45:04 -07:00
8fb96934ca panic when radio does not start 2016-04-15 22:41:30 -07:00
cd91504c1f fix help urls 2016-04-15 16:54:44 -07:00
91e8196621 0.2.77 2016-04-15 16:47:36 -07:00
26841de6cf bring back 'write number' 2016-04-15 16:40:51 -07:00
24f2a45310 0.2.76 2016-04-15 16:36:40 -07:00
67c5f0612a added serial docs 2016-04-15 16:36:31 -07:00
d7c3f1b50a various docs fixes 2016-04-15 16:15:08 -07:00
2fb6025848 fixed banana 2016-04-15 16:02:50 -07:00
8da3c5eb84 various docs fixes 2016-04-15 15:53:20 -07:00
4ee1799271 more docs 2016-04-15 15:40:55 -07:00
953ea31016 0.2.75 2016-04-15 15:27:30 -07:00
9fe27d5f35 Bump pxt-core to 0.2.81 2016-04-15 15:27:28 -07:00
d290aeb2e9 udpated favicon 2016-04-15 15:27:21 -07:00
7fee84678a missing favicon 2016-04-15 15:10:35 -07:00
77030db1d3 fixing links in docs 2016-04-15 15:02:26 -07:00
bb6ae00a49 moving out outdated js docs 2016-04-15 14:37:25 -07:00
6515cc0360 0.2.74 2016-04-15 08:17:45 -07:00
13d09b3e83 Bump pxt-core to 0.2.79 2016-04-15 08:17:43 -07:00
3a434197a3 updated neopixel 2016-04-15 07:42:52 -07:00
254 changed files with 613 additions and 621 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@ temp
projects
win10/app/bin
win10/app/bld
win10/*.opendb
*.user
*.sw?

View File

@ -69,7 +69,11 @@ When your micro:bit isnt 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

View File

@ -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

View File

@ -2,7 +2,9 @@
The micro:bit LED screen
![](/static/mb/device/screen-0.png)
```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
View 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.
![](/static/mb/serial-library-0.png)
* (optional): in the "Terminal" section, check "implicit cr in every lf"
![](/static/mb/serial-library-1.png)
### 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
View 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()
```

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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!

View File

@ -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!

View File

@ -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)

View File

@ -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)

View File

@ -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!

View File

@ -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

View File

@ -1,41 +0,0 @@
# crocodile clip activity
Use the crocodile clips
# micro:bit crocodile clip
![](/static/mb/blocks/lessons/crocodile-clip-0.jpg)
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
![](/static/mb/lessons/banana-keyboard-1.png)
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
### Step 2
![](/static/mb/crocodile-clips-2.jpg)
Using the 1st crocodile clip, connect the unattached end of the crocodile clip onto the 0 pin on the micro:bit.
### Step 3
![](/static/mb/blocks/lessons/crocodile-clip-0.jpg)
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.

View File

@ -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!

View File

@ -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)

View File

@ -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

View File

@ -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!

View File

@ -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!

View File

@ -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!

View File

@ -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)

View File

@ -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!

View File

@ -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)
### ~

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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
![](/static/mb/blocks/comment-0.png)
### 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)

View File

@ -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
![](/static/mb/on-gamepad-button-0.png)
### 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)

View File

@ -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
![](/static/mb/on-signal-strength-changed-0.png)
### KindScript
```
export function onSignalStrengthChanged(body:td.Action)
```sig
devices.onSignalStrengthChanged(() => {})
```
### Parameters

View File

@ -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
![](/static/mb/raise-alert-to-0.png)
### KindScript
```
```sig
export function raiseAlertTo(event: string)
```

View File

@ -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
![](/static/mb/receive-number-0.png)
### KindScript
```
export function receiveNumber() : number
```sig
radio.receiveNumber();
```
### Returns

View File

@ -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
![](/static/mb/signal-strength-0.png)
### KindScript
```
export function signalStrength() : number
devices.signalStrength() : number
```
### Returns

View File

@ -14,7 +14,7 @@ The set of supported events will depend on the remote device and the BBC micro:b
![](/static/mb/tell-camera-to-0.png)
### KindScript
### JavaScript
```
export function tellCameraTo(event: string)

View File

@ -10,7 +10,7 @@ The functions in the antenna namespace allow the BBC micro:bit to communicate wi
![](/static/mb/tell-microphone-to-0.png)
### 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)

View File

@ -14,7 +14,7 @@ The set of supported events will depend on the remote device and the BBC micro:b
![](/static/mb/tell-remote-control-to-0.png)
### KindScript
### JavaScript
```
export function tellRemoteControlTo(event: string)

View 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)

View File

@ -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.
![](/static/mb/change-score-by-0.png)
## 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)

View File

@ -1,16 +1,12 @@
# Change
The game library
### Change
Sprite will change the x position by this number
## Block Editor
### Block Editor
![](/static/mb/change-0.png)
## KindScript
### JavaScript
Sprite will change the x position by this number

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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
![](/static/mb/scroll-image-0.png)
### 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)

View File

@ -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)

View File

@ -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)

View File

@ -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
![](/static/mb/show-image-0.png)
### 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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -28,5 +28,5 @@ basic.forever(() => {
### See also
[compass heading](/input/compass-heading)
[compass heading](/reference/input/compass-heading)

View File

@ -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, () => {})

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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:
![](/static/mb/offline-2.png)

View File

@ -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).

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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
View 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);
```

View 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)

View 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)

View File

@ -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)

View File

@ -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`:
![](/static/mb/blocks/number-3.png)
@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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:
![](/static/mb/blocks/var-0.png)
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
![](/static/mb/blocks/var-1.png)
// number variable
![](/static/mb/blocks/var-2.png)
// boolean variable
![](/static/mb/blocks/var-3.png)
// image variable
![](/static/mb/blocks/var-4.png)
See [Image](/blocks/image) for info on creating and using image variables.
The resulting code should look something like this:
![](/static/mb/blocks/var-5.png)
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:
![](/static/mb/blocks/var-6.png)
```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:
![](/static/mb/blocks/var-7.png)
```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:
![](/static/mb/blocks/var-8.png)
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):
![](/static/mb/blocks/var-9.png)
```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:
![](/static/mb/blocks/comment-0.png)
```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

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -11,9 +11,13 @@
"dependencies": {
"microbit": "file:../microbit"
},
"microbit": {
"yotta": {
"config": {
"MICROBIT_BLE_ENABLED": "1"
"microbit-dal": {
"bluetooth": {
"enabled": 1
}
}
}
},
"installedVersion": "zakvul"

View File

@ -12,10 +12,14 @@
"dependencies": {
"microbit": "file:../microbit"
},
"microbit": {
"yotta": {
"config": {
"MICROBIT_BLE_ENABLED": "0"
"microbit-dal": {
"bluetooth": {
"enabled": 0
}
}
}
},
"installedVersion": "rlfgis"
}
}

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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

View File

@ -281,5 +281,7 @@ declare namespace serial {
Int32BE = 10,
// UInt32,
}
declare namespace storage {
}
// Auto-generated. Do not edit. Really.

View File

@ -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();
}
/**

View File

@ -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);
}
}

View File

@ -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
}
}
}
}
}

View File

@ -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);

View File

@ -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
View 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();
}
}

View File

@ -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