461 lines
7.4 KiB
Markdown
461 lines
7.4 KiB
Markdown
|
# Reference
|
||
|
|
||
|
### @section full
|
||
|
|
||
|
### ~column
|
||
|
|
||
|
### Basic
|
||
|
|
||
|
[show number](/microbit/reference/basic/show-number)
|
||
|
|
||
|
~~~~block
|
||
|
basic.showNumber(2)
|
||
|
~~~~
|
||
|
|
||
|
[show string](/microbit/reference/basic/show-string)
|
||
|
|
||
|
~~~~block
|
||
|
basic.showString('Hello!')
|
||
|
~~~~
|
||
|
|
||
|
[show LEDs](/microbit/reference/basic/show-leds)
|
||
|
|
||
|
~~~~block
|
||
|
basic.showLeds(`. . . . .
|
||
|
. # . # .
|
||
|
. . . . .
|
||
|
# . . . #
|
||
|
. # # # .`)
|
||
|
~~~~
|
||
|
|
||
|
[clear screen](/microbit/reference/basic/clear-screen)
|
||
|
|
||
|
~~~~block
|
||
|
basic.clearScreen()
|
||
|
~~~~
|
||
|
|
||
|
[forever](/microbit/reference/basic/forever)
|
||
|
|
||
|
~~~~block
|
||
|
basic.forever(() => { })
|
||
|
~~~~
|
||
|
|
||
|
[pause](/microbit/reference/basic/pause)
|
||
|
|
||
|
```block
|
||
|
basic.pause(200)
|
||
|
```
|
||
|
|
||
|
### Input
|
||
|
|
||
|
[on button pressed](/microbit/reference/input/on-button-pressed)
|
||
|
|
||
|
```block
|
||
|
input.onButtonPressed(Button.A, () => {})
|
||
|
```
|
||
|
|
||
|
[on pin pressed](/microbit/reference/input/on-pin-pressed)
|
||
|
|
||
|
```block
|
||
|
input.onPinPressed(TouchPin.P0, () => {})
|
||
|
```
|
||
|
|
||
|
[on shake](/microbit/reference/input/on-shake)
|
||
|
|
||
|

|
||
|
|
||
|
[on logo up](/microbit/reference/on-logo-up)
|
||
|
|
||
|

|
||
|
|
||
|
[on logo down](/microbit/reference/on-logo-down)
|
||
|
|
||
|

|
||
|
|
||
|
[on screen up](/microbit/reference/on-screen-up)
|
||
|
|
||
|

|
||
|
|
||
|
[on screen down](/microbit/reference/on-screen-down)
|
||
|
|
||
|

|
||
|
|
||
|
[button is pressed](/microbit/reference/button-is-pressed)
|
||
|
|
||
|

|
||
|
|
||
|
[compass heading](/microbit/reference/compass-heading)
|
||
|
|
||
|

|
||
|
|
||
|
[temperature](/microbit/reference/temperature)
|
||
|
|
||
|

|
||
|
|
||
|
[acceleration](/microbit/reference/input/acceleration)
|
||
|
|
||
|

|
||
|
|
||
|
[rotation](/microbit/reference/rotation)
|
||
|
|
||
|

|
||
|
|
||
|
[magnetic force](/microbit/reference/magnetic-force)
|
||
|
|
||
|

|
||
|
|
||
|
[running time](/microbit/reference/running-time)
|
||
|
|
||
|

|
||
|
|
||
|
### Loops
|
||
|
|
||
|
[for](/microbit/reference/loops/for)
|
||
|
|
||
|
```block
|
||
|
for(let i = 0;i<5;i++) {}
|
||
|
```
|
||
|
|
||
|
[repeat](/microbit/reference/loops/repeat)
|
||
|
|
||
|

|
||
|
|
||
|
[while](/microbit/reference/loops/while)
|
||
|
|
||
|
```block
|
||
|
while(true) {}
|
||
|
```
|
||
|
|
||
|
[forever](/microbit/reference/basic/forever)
|
||
|
|
||
|
```block
|
||
|
basic.forever(() => {})
|
||
|
```
|
||
|
|
||
|
|
||
|
|
||
|
### ~
|
||
|
|
||
|
### ~column
|
||
|
|
||
|
### Logic
|
||
|
|
||
|
[if](/microbit/reference/logic/if)
|
||
|
|
||
|
```block
|
||
|
if(false) {
|
||
|
}
|
||
|
```
|
||
|
|
||
|
[Boolean](/microbit/reference/types/boolean) values: *true*; *false*
|
||
|
|
||
|
```block
|
||
|
true
|
||
|
false
|
||
|
```
|
||
|
|
||
|
Boolean binary operators: *and* (conjunction); *or* (disjunction)
|
||
|
|
||
|
```block
|
||
|
true && false;
|
||
|
true || false;
|
||
|
```
|
||
|
|
||
|
Boolean negation operator
|
||
|
|
||
|
```block
|
||
|
!true
|
||
|
```
|
||
|
|
||
|
Comparison operators (=, !=, <, >, <=, >=)
|
||
|
|
||
|
```block
|
||
|
0 == 0;
|
||
|
1 !- 0;
|
||
|
0 < 1;
|
||
|
1 > 0;
|
||
|
0 <= 1;
|
||
|
1 >= 0;
|
||
|
```
|
||
|
|
||
|
### Variables
|
||
|
|
||
|
[Assign](/microbit/reference/variables/assign) (set) a variable's value
|
||
|
|
||
|
```block
|
||
|
let x = 0;
|
||
|
```
|
||
|
|
||
|
Get a variable's value
|
||
|
|
||
|
```block
|
||
|
let x = 0;
|
||
|
x;
|
||
|
```
|
||
|
|
||
|
[Change](/microbit/reference/variables/change-var) a variable's value
|
||
|
|
||
|
```block
|
||
|
let x = 0;
|
||
|
x+=1;
|
||
|
```
|
||
|
|
||
|
### Math
|
||
|
|
||
|
[Numeric](/microbit/reference/types/number) values: 0, 1, 2, ...
|
||
|
|
||
|
```block
|
||
|
0;
|
||
|
1;
|
||
|
2;
|
||
|
```
|
||
|
|
||
|
Arithmetic binary operation (+, -, *, /)
|
||
|
|
||
|
```block
|
||
|
0+1;
|
||
|
0-1;
|
||
|
1*2;
|
||
|
3/4;
|
||
|
```
|
||
|
|
||
|
Absolute value
|
||
|
|
||
|
```block
|
||
|
Math.abs(-5);
|
||
|
```
|
||
|
|
||
|
Minimum/maximum of two values
|
||
|
|
||
|
```block
|
||
|
Math.min(0, 1);
|
||
|
Math.max(0, 1);
|
||
|
```
|
||
|
|
||
|
Random value
|
||
|
|
||
|
```block
|
||
|
Math.random(5);
|
||
|
```
|
||
|
|
||
|
### LED
|
||
|
|
||
|
[plot](/microbit/reference/led/plot)
|
||
|
|
||
|
```block
|
||
|
led.plot(2,2)
|
||
|
```
|
||
|
|
||
|
[unplot](/microbit/reference/led/unplot)
|
||
|
|
||
|
```block
|
||
|
led.unplot(2,2)
|
||
|
```
|
||
|
|
||
|
[point](/microbit/reference/point)
|
||
|
|
||
|
```block
|
||
|
led.point(2,2)
|
||
|
```
|
||
|
|
||
|
[brightness](/microbit/reference/brightness)
|
||
|
|
||
|
```block
|
||
|
led.brightness()
|
||
|
```
|
||
|
|
||
|
[set brightness](/microbit/reference/set-brightness)
|
||
|
|
||
|
```block
|
||
|
led.setBrightness(255)
|
||
|
```
|
||
|
|
||
|
[stop animation](/microbit/reference/stop-animation)
|
||
|
|
||
|
```block
|
||
|
led.stopAnimation()
|
||
|
```
|
||
|
|
||
|
[plot bar graph](/microbit/reference/led/plot-bar-graph)
|
||
|
|
||
|
```block
|
||
|
led.plotBarGraph(0, 1023)
|
||
|
```
|
||
|
|
||
|
### Game
|
||
|
|
||
|
[create sprite](/microbit/reference/game/create-sprite)
|
||
|
|
||
|

|
||
|
|
||
|
[move](/microbit/reference/game/move)
|
||
|
|
||
|

|
||
|
|
||
|
[turn](/microbit/reference/game/turn)
|
||
|
|
||
|

|
||
|
|
||
|
[change](/microbit/reference/game/change)
|
||
|
|
||
|

|
||
|
|
||
|
[set](/microbit/reference/game/set)
|
||
|
|
||
|

|
||
|
|
||
|
[reports](/microbit/reference/reports)
|
||
|
|
||
|

|
||
|
|
||
|
[touching](/microbit/reference/touching)
|
||
|
|
||
|

|
||
|
|
||
|
[touching edge](/microbit/reference/touching-edge)
|
||
|
|
||
|

|
||
|
|
||
|
[if on edge, bounce](/microbit/reference/logic/if-on-edge-bounce)
|
||
|
|
||
|

|
||
|
|
||
|
[change score by](/microbit/reference/change-score-by)
|
||
|
|
||
|

|
||
|
|
||
|
[score](/microbit/reference/score)
|
||
|
|
||
|

|
||
|
|
||
|
[start countdown](/microbit/reference/start-countdown)
|
||
|
|
||
|

|
||
|
|
||
|
[game over](/microbit/reference/game-over)
|
||
|
|
||
|

|
||
|
|
||
|
### Music
|
||
|
|
||
|
[play tone](/microbit/reference/play-tone)
|
||
|
|
||
|

|
||
|
|
||
|
[ring tone](/microbit/reference/ring-tone)
|
||
|
|
||
|

|
||
|
|
||
|
[rest](/microbit/reference/rest)
|
||
|
|
||
|

|
||
|
|
||
|
[tempo](/microbit/reference/tempo)
|
||
|
|
||
|

|
||
|
|
||
|
[set tempo](/microbit/reference/set-tempo)
|
||
|
|
||
|

|
||
|
|
||
|
[change tempo](/microbit/reference/music/set-tempo)
|
||
|
|
||
|

|
||
|
|
||
|
### Comments
|
||
|
|
||
|
[comment](/microbit/reference/comment)
|
||
|
|
||
|
### Images
|
||
|
|
||
|
[show image](/microbit/reference/show-image)
|
||
|
|
||
|

|
||
|
|
||
|
[scroll image](/microbit/reference/scroll-image)
|
||
|
|
||
|

|
||
|
|
||
|
[create image](/microbit/reference/create-image)
|
||
|
|
||
|

|
||
|
|
||
|
|
||
|
### ~
|
||
|
|
||
|
### ~column
|
||
|
|
||
|
### Pins
|
||
|
|
||
|
[digital read pin](/microbit/reference/pins/digital-read-pin)
|
||
|
|
||
|

|
||
|
|
||
|
[digital write pin](/microbit/reference/pins/digital-write-pin)
|
||
|
|
||
|

|
||
|
|
||
|
[analog read pin](/microbit/reference/pins/analog-read-pin)
|
||
|
|
||
|

|
||
|
|
||
|
[analog write pin](/microbit/reference/pins/analog-write-pin)
|
||
|
|
||
|

|
||
|
|
||
|
[analog set period](/microbit/reference/pins/analog-set-period)
|
||
|
|
||
|

|
||
|
|
||
|
[servo write pin](/microbit/reference/pins/servo-write-pin)
|
||
|
|
||
|

|
||
|
|
||
|
[servo set pulse](/microbit/reference/pins/servo-set-pulse)
|
||
|
|
||
|

|
||
|
|
||
|
[map](/microbit/reference/map)
|
||
|
|
||
|

|
||
|
|
||
|
|
||
|
## Devices
|
||
|
|
||
|
Functions in this category require to be connected to a remote device.
|
||
|
|
||
|
[tell camera to](/microbit/reference/devices/tell-camera-to)
|
||
|
|
||
|

|
||
|
|
||
|
[tell remote control to](/microbit/reference/devices/tell-remote-control-to)
|
||
|
|
||
|

|
||
|
|
||
|
[raise alert to](/microbit/reference/devices/raise-alert-to)
|
||
|
|
||
|

|
||
|
|
||
|
[on notified](/microbit/reference/on-notified)
|
||
|
|
||
|

|
||
|
|
||
|
[on gamepad button](/microbit/reference/on-gamepad-button)
|
||
|
|
||
|

|
||
|
|
||
|
[on notified](/microbit/reference/on-notified)
|
||
|
|
||
|

|
||
|
|
||
|
[signal strength](/microbit/reference/signal-strength)
|
||
|
|
||
|

|
||
|
|
||
|
[on signal strength changed](/microbit/reference/on-signal-strength-changed)
|
||
|
|
||
|

|
||
|
|
||
|
### ~
|
||
|
|