Compare commits

...

8 Commits

Author SHA1 Message Date
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
33 changed files with 242 additions and 146 deletions

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

@ -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,11 +32,21 @@ 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
@ -44,14 +56,14 @@ Instead of turning individual LEDs on or off, as above, you can display an [imag
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`.

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

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

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

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

@ -42,13 +42,13 @@ 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

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

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

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

@ -37,5 +37,5 @@ basic.showString(s)
### 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

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

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

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

@ -55,5 +55,5 @@ To learn more about how the BBC micro:bit queues up and schedules event handlers
### see also
[on button pressed](/reference/input/on-button-pressed), [on logo up](/functions/on-logo-up), [on logo down](/functions/on-logo-down), [on screen up](/functions/on-screen-up), [on screen down](/functions/on-screen-down), [on shake](/reference/input/on-gesture), [on pin pressed](/reference/input/on-pin-pressed)
[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,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

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

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

@ -7,6 +7,7 @@ namespace serial {
* Prints a line of text to the serial
* @param value to send over serial
*/
//% help=/reference/serial/write-line
//% blockId=serial_writeline block="serial|write %text"
export function writeLine(text: string): void {
writeString(text);

View File

@ -1,6 +1,6 @@
{
"name": "pxt-microbit",
"version": "0.2.75",
"version": "0.2.77",
"description": "BBC micro:bit target for PXT",
"keywords": [
"JavaScript",