Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Martin Woolley
2016-06-21 08:08:12 +01:00
103 changed files with 2418 additions and 489 deletions

View File

@ -6,9 +6,9 @@ Turn off all the LED lights on the [LED screen](/device/screen).
basic.clearScreen()
```
### Example: vanishing heart
### Example: Vanishing heart
The following code shows a heart on the screen and then turns off all the LED lights using `clear screen`:
The following code shows a heart on the screen and then turns off all the LED lights.
```blocks
basic.showLeds(`
@ -23,5 +23,5 @@ basic.clearScreen()
### See also
[set brightness](/reference/led/set-brightness), [unplot](/reference/led/unplot), [plot](/reference/led/plot), [Image](/reference/images/image), [clear](/reference/basic/clear-screen)
[set brightness](/reference/led/set-brightness), [unplot](/reference/led/unplot), [plot](/reference/led/plot), [Image](/reference/images/image)

View File

@ -2,12 +2,13 @@
Register code to run when the micro:bit receives a command from the paired gamepad.
## 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).
### ~hint
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.
### ~
```sig
devices.onGamepadButton(MesDpadButtonInfo.ADown, () => {})
@ -20,3 +21,7 @@ devices.onGamepadButton(MesDpadButtonInfo.ADown, () => {})
### See Also
[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)
```package
microbit-devices
```

View File

@ -1,15 +1,16 @@
# On Signal Strength Changed
The `on signal strength changed` function.
Register code to run when the signal strength of the paired device changes.
## 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).
### ~hint
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.
### ~
```sig
devices.onSignalStrengthChanged(() => {})
```
@ -30,5 +31,8 @@ devices.onSignalStrengthChanged(() => {
### 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)
[tell remote control to](/reference/devices/tell-remote-control-to), [raise alert to](/reference/devices/raise-alert-to), [signal strength](/reference/devices/signal-strength)
```package
microbit-devices
```

View File

@ -1,15 +1,15 @@
# raise alert to
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).
### ~hint
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.
### ~
```sig
export function raiseAlertTo(event: string)
@ -23,41 +23,44 @@ export function raiseAlertTo(event: string)
To tell the connected device to display toast
```
```blocks
devices.raiseAlertTo("display toast")
```
To tell the connected device to vibrate
```
```blocks
devices.raiseAlertTo("vibrate")
```
To tell the connected device to play a sound
```
```blocks
devices.raiseAlertTo("play sound")
```
To tell the connected device to play a ringtone
```
```blocks
devices.raiseAlertTo("play ringtone")
```
To tell the connected device to find my phone
```
```blocks
devices.raiseAlertTo("find my phone")
```
To tell the connected device to ring alarm
```
```blocks
devices.raiseAlertTo("ring alarm")
```
### See also
[tell remote control to](/reference/devices/tell-remote-control-to), [tell camera to](/reference/devices/tell-camera-to), [on notified](/reference/devices/on-notified)
[tell remote control to](/reference/devices/tell-remote-control-to), [tell camera to](/reference/devices/tell-camera-to)
```package
microbit-devices
```

View File

@ -1,36 +0,0 @@
# Receive Number
The broadcast function.
Reads the next radio packet as a number data packet.
## Important Security Consideration
The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits.
This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place.
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.receiveNumber();
```
### Returns
* packet - a number received.
### Examples
Broadcasts the value of ``acceleration`` x to other micro:bits.
```
radio.onDataReceived(() => {
led.plotBarGraph(radio.receiveNumber(), 1023)
})
```
### See also
[send number](/reference/radio/send-number), [receive number](/reference/radio/receive-number), [on data received](/reference/radio/on-data-received), [set group](/reference/radio/set-group)

View File

@ -1,17 +1,17 @@
# Signal Strength
The `signal strength` function.
Returns the signal strength reported by the paired device from ``0`` (no signal) to ``4`` (full strength).
## 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).
### ~hint
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.
```
devices.signalStrength() : number
### ~
```sig
devices.signalStrength();
```
### Returns
@ -22,7 +22,7 @@ devices.signalStrength() : number
Display the signal strength on screen:
```
```blocks
devices.onSignalStrengthChanged(() => {
basic.showNumber(devices.signalStrength(), 150)
})
@ -30,5 +30,8 @@ devices.onSignalStrengthChanged(() => {
### 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), [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), [on signal strength changed](/reference/devices/on-signal-strength-changed)
```package
microbit-devices
```

View File

@ -1,23 +1,17 @@
# tell camera to
The tell camera to function.
Access the photo/video-taking functionality of a remote device using the ``tell camera to`` function.
## 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).
### ~hint
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/tell-camera-to-0.png)
### JavaScript
```
export function tellCameraTo(event: string)
```sig
devices.tellCameraTo()
```
### Parameters
@ -28,53 +22,56 @@ export function tellCameraTo(event: string)
To tell the connected device to take a picture:
```
```blocks
devices.tellCameraTo("take photo")
```
To tell the connected device to start recording a video
```
```blocks
devices.tellCameraTo("start video capture")
```
To tell the connected device to stop recording a video
```
```blocks
devices.tellCameraTo("stop video capture")
```
To tell the connected device to toggle front-rear
```
```blocks
devices.tellCameraTo("toggle front-rear")
```
To tell the connected device to launch photo mode
```
```blocks
devices.tellCameraTo("launch photo mode")
```
To tell the connected device to launch video mode
```
```blocks
devices.tellCameraTo("launch video mode")
```
To tell the connected device to stop photo mode
```
```blocks
devices.tellCameraTo("stop photo mode")
```
To tell the connected device to stop video mode
```
```blocks
devices.tellCameraTo("stop video mode")
```
### 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)
[tell remote control to](/reference/devices/tell-remote-control-to), [raise alert to](/reference/devices/raise-alert-to)
```package
microbit-devices
```

View File

@ -45,14 +45,3 @@ To tell the connected device to stop recording audio
```
devices.tellMicrophoneTo("stop capture")
```
### Other show functions
* use [tell remote control to](/reference/devices/tell-remote-control-to) to control presentation of media content
* use [tell camera to](/reference/devices/tell-camera-to) to control the photo/video recording of connected devices
* use [raise alert to](/reference/devices/raise-alert-to) to control the microphone of connected devices
### See also
[Devices](/reference/devices)

View File

@ -1,23 +1,17 @@
# tell remote control to
The tell remote control to function.
Control the presentation of media content available on a remote device using the `tell remote control` to function.
##
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).
### ~hint
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/tell-remote-control-to-0.png)
### JavaScript
```
export function tellRemoteControlTo(event: string)
```sig
devices.tellRemoteControlTo(event: string)
```
### Parameters
@ -40,53 +34,57 @@ export function tellRemoteControlTo(event: string)
To tell the connected device to start playing:
```
```blocks
devices.tellRemoteControlTo("play")
```
To tell the connected device to stop playing
```
```blocks
devices.tellRemoteControlTo("stop")
```
To tell the connected device to go to next track
```
```blocks
devices.tellRemoteControlTo("next track")
```
To tell the connected device to go to previous track
```
```blocks
devices.tellRemoteControlTo("previous track")
```
To tell the connected device to go forward
```
```blocks
devices.tellRemoteControlTo("forward")
```
To tell the connected device to rewind
```
```blocks
devices.tellRemoteControlTo("rewind")
```
To tell the connected device volume up
```
```blocks
devices.tellRemoteControlTo("volume up")
```
To tell the connected device volume down
```
```blocks
devices.tellRemoteControlTo("volume down")
```
### See also
[tell camera to](/reference/devices/tell-camera-to), [raise alert to](/reference/devices/raise-alert-to), [on notified](/reference/devices/on-notified)
[tell camera to](/reference/devices/tell-camera-to), [raise alert to](/reference/devices/raise-alert-to)
```package
microbit-devices
```

View File

@ -0,0 +1,46 @@
# Create Big Image
Make a big [image](/reference/images/image) (picture) for the micro:bit
[LED screen](/device/screen). The big image made of two squares.
Each of the squares is five LEDs on a side, like a regular image.
```blocks
images.createBigImage(`
. . # . . . . # . .
. # # # . . . # . .
# . # . # # . # . #
. . # . . . # # # .
. . # . . . . # . .
`);
```
### Example: Flip-flopping arrow
This program makes a big image with a picture of an arrow pointing up,
and an arrow pointing down. If you press button `A`, the program will
show the arrow pointing up, which starts `0` LEDs from the left in the
big image. If you press button `B`, the program will show the arrow
pointing down, which starts `5` LEDs from the left.
```blocks
let arrows = images.createBigImage(`
. . # . . . . # . .
. # # # . . . # . .
# . # . # # . # . #
. . # . . . # # # .
. . # . . . . # . .
`);
input.onButtonPressed(Button.A, () => {
arrows.showImage(0);
});
input.onButtonPressed(Button.B, () => {
arrows.showImage(5);
});
```
### See also
[Getting Started](/getting-started), [image](/reference/images/image),
[create image](/reference/images/create-image),
[show image](/reference/images/show-image),
[scroll image](/reference/images/scroll-image), [show animation](/reference/basic/show-animation)

View File

@ -1,6 +1,7 @@
# Create Image
Create an [Image](/reference/images/image) to show on the [LED screen](/device/screen).
Make an [image](/reference/images/image) (picture) for the micro:bit
[LED screen](/device/screen).
```sig
images.createImage(`
@ -12,24 +13,37 @@ images.createImage(`
`)
```
### Example: rock, paper, scissors
### Example: Flip-flopping arrow
The following example shows one of three images (rock, paper, or scissors) when you shake the micro:bit:
If you press button `A`, this program will make a picture of an
arrow and show it on the LED screen. If you press button `B`, the
program will show a picture of the arrow upside-down.
```
input.onGesture(Gesture.Shake, () => {
let rockpaper = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
rockpaper.showFrame(Math.random(3))
})
```blocks
input.onButtonPressed(Button.A, () => {
images.createImage(`
. . # . .
. # # # .
# . # . #
. . # . .
. . # . .
`).showImage(0);
});
input.onButtonPressed(Button.B, () => {
images.createImage(`
. . # . .
. . # . .
# . # . #
. # # # .
. . # . .
`).showImage(0);
});
```
### See also
[show animation](/reference/basic/show-animation), [image](/reference/images/image), [show image](/reference/image/show-image), [scroll image](/reference/image/scroll-image)
[Getting Started](/getting-started), [image](/reference/images/image),
[create big image](/reference/images/create-big-image),
[show image](/reference/images/show-image),
[scroll image](/reference/images/scroll-image), [show animation](/reference/basic/show-animation)

View File

@ -1,70 +1,45 @@
# Scroll Image
The scroll image function.
Scrolls the frames within an [Image](/reference/images/image) on the [LED screen](/device/screen).
### Block Editor
![](/static/mb/scroll-image-0.png)
### JavaScript
```
export function scrollImage(_this: micro_bit.Image, xOffsetPerStep: number, interval: number)
```
Scroll (slide) an [image](/reference/images/image) (picture) from one
side to the other of the [LED screen](/device/screen).
### Parameters
* x offset per step : [Number](/reference/types/number) - the number of columns to scroll at a time (horizontal offset). Use a positive number to scroll an image to the right and a negative number to scroll left. To jump from one image frame to the next, use an offset of 5 or -5.
* interval (ms) : [Number](/reference/types/number) - the time (in milliseconds) before scrolling by `x offset per step`; the larger the number, the slower the scroll.
* ``offset`` is a [number](/reference/types/number) that means
how many LEDs to scroll at a time, from right to left or
left to right. If you use a positive number like `2`, the image
will scroll from the right side of the screen to the left.
If you use a negative number like `-2`, the image will scroll
in the other direction. If you use `5` or `-5`, the image
will scroll one **frame** at a time. (A frame is a part of the
image. It is a square with five LEDs on a side). This is
useful for **animation**.
### ~hide
* ``interval (ms)`` is a [number](/reference/types/number) that means
how many milliseconds to wait before scrolling the amount that
``offset`` says. (1000 milliseconds is one second.) The bigger you
make this number, the slower the image will scroll.
```
let img = images.createImage(`
. . # . . . # # # . . # # # .
. . # . . . . . # . . . . # .
. . # . . . . # . . . # # # .
. . # . . . # . . . . . . # .
. . # . . . # # # . . # # # .
`)
```
### Example
### ~
This program scrolls an image of two arrows five LEDs at a time,
with a pause of 200 milliseconds between each time it scrolls.
Because each frame is five LEDs wide, that means this program
will look like it's animating one arrow flipping and flopping.
Of course, you can use any two frames you want instead.
To scroll an image 1 column at a time to the right:
```
img.scrollImage(1, 1000)
```
To scroll an image 5 columns at a time (skip from frame to frame):
```
img.scrollImage(5, 1000)
```
To scroll an image 1 column at a time to the left:
```
img.scrollImage(-1, 500)
```
### Example: scroll through frames
This example creates an image with 3 frames, then scrolls through the 3 frames:
```
img = images.createImage(`
. . # . . . # # # . . # # # .
. . # . . . . . # . . . . # .
. . # . . . . # . . . # # # .
. . # . . . # . . . . . . # .
. . # . . . # # # . . # # # .
`)
img.showImage(0)
img.scrollImage(5, 1000)
```blocks
let arrows = images.createBigImage(`
. . # . . . . # . .
. # # # . . . # . .
# . # . # # . # . #
. . # . . . # # # .
. . # . . . . # . .
`);
basic.forever(() => {
arrows.scrollImage(5, 200);
});
```
### See also

View File

@ -1,51 +1,42 @@
# Show Image
The show image function.
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)
```
Show an [image](/reference/images/image) (picture) on the
[LED screen](/device/screen). After the micro:bit shows an image, it
will pause for 400 milliseconds (1000 milliseconds is one second).
### Parameters
* x offset - [Number](/reference/types/number); the horizontal starting point of an image; use 0 for the first frame of the image, 5 for the second frame of the image, 10 for the third frame and so on.
* an [image](/reference/images/image) (picture). It is usually a square with five LEDs on a side, but it might be wider.
* a [number](/reference/types/number) that says how many LEDs from the left of the picture the micro:bit should start. `0` means start at the first **frame** of the picture, `5` means start at the second frame, `10` means start at the third, and so on.
### Create image and show image
### Example: Flip-flopping arrow
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:
This program makes a big image with a frame of an arrow pointing up,
and a frame of an arrow pointing down. If you press button `A`, the
program will use ``show image`` to show the arrow pointing up. (It
starts `0` LEDs from the left in the big image.) If you press button
`B`, the program will use ``show image`` to show the arrow pointing
down, which starts `5` LEDs from the left.
```
let img = images.createImage(`
. . # . .
. # . # .
. . # . .
. # . # .
. . # . .
`)
img.showImage(0)
```
### Example: display numbers 1-5
The following example creates an image with 5 frames and then uses a [for loop](/blocks/loops/for) to show each frame on the screen:
```
let img2 = images.createImage(`
. . # . . . # # # # . # # # . . . . # . . # # # .
. # # . . . . . . # . . . # . . . # # . . # . . .
. . # . . . . . # . . . # . . . # # # # . # # # .
. . # . . . . # . . . . . # . . . . # . . . . # .
. . # . . . # # # # . # # # . . . . # . . # # # .
`)
for (let i = 0; i < 5; i++) {
img2.showImage(i * 5)
basic.pause(1000)
}
```blocks
let arrows = images.createBigImage(`
. . # . . . . # . .
. # # # . . . # . .
# . # . # # . # . #
. . # . . . # # # .
. . # . . . . # . .
`);
input.onButtonPressed(Button.A, () => {
arrows.showImage(0);
});
input.onButtonPressed(Button.B, () => {
arrows.showImage(5);
});
```
### See also
[show animation](/reference/basic/show-animation), [image](/reference/images/image), [create image](/reference/images/create-image), [scroll image](/reference/images/scroll-image)
[Getting Started](/getting-started), [image](/reference/images/image),
[create image](/reference/images/create-image),
[create big image](/reference/images/create-big-image),
[scroll image](/reference/images/scroll-image), [show animation](/reference/basic/show-animation)

View File

@ -56,5 +56,5 @@ for (let i = 0; i < img2.width() / 5; i++) {
### See also
[show image](/reference/images/show-image), [image](/reference/image/image), [create image](/reference/images/create-image), [scroll image](/reference/images/scroll-image), [show animation](/reference/basic/show-animation)
[show image](/reference/images/show-image), [image](/reference/images/image), [create image](/reference/images/create-image), [scroll image](/reference/images/scroll-image), [show animation](/reference/basic/show-animation)

View File

@ -1,11 +1,11 @@
# Send Number
# Send Value
Broadcast a (name,number) pair to other micro:bits connected via ``radio``.
Send a [string]() and [number]() together by ``radio`` to other micro:bits.
### Parameters
* name - a string to send
* num - a number to send.
* a [string](/reference/types/string) to send by radio
* a [number](/reference/types/number) to send by radio
### Simulator
@ -13,16 +13,29 @@ This function only works on the micro:bit, not in browsers.
### Example: Broadcasting acceleration
This example broadcasts the value of your micro:bit's ``acceleration`` in the `x` direction
(left and right) to other micro:bits.
This kind of program might be useful in a model car or model rocket.
This program sends your micro:bit's **acceleration** (amount it is
speeding up or slowing down) in the `x` direction (left and right) to
other micro:bits. This kind of program might be useful in a model car
or model rocket.
```blocks
radio.setGroup(99)
input.onButtonPressed(Button.A, () => {
radio.sendValue("acc",input.acceleration(Dimension.X))
})
```
This program receives the string and number sent by the last program.
Then it shows them on the LED screen.
```blocks
radio.setGroup(99)
radio.onDataReceived(() => {
basic.showString(radio.receiveString());
basic.showNumber(radio.receiveNumber());
});
```
### See also
[receive number](/reference/radio/receive-number), [on data received](/reference/radio/on-data-received)

View File

@ -57,7 +57,7 @@ let brightness = led.brightness()
### Math functions
The [math library](/reference/math) includes math related functions.
The [math library](/blocks/math) includes math related functions.
For example, the `absolute` function returns the returns the absolute value of input parameter `x`:
```blocks