2016-03-26 00:47:20 +01:00
|
|
|
# Reference
|
|
|
|
|
2016-04-05 22:23:42 +02:00
|
|
|
## micro:bit
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-04-05 22:23:42 +02:00
|
|
|
```namespaces
|
|
|
|
basic.showString("Hello!");
|
|
|
|
input.onButtonPressed(Button.A, () => {});
|
|
|
|
led.plot(0,0);
|
|
|
|
radio.sendNumber(0);
|
|
|
|
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Whole));
|
2016-04-06 00:59:25 +02:00
|
|
|
game.createSprite(2,2);
|
2016-04-05 22:23:42 +02:00
|
|
|
pins.digitalReadPin(DigitalPin.P0);
|
2016-04-06 00:59:25 +02:00
|
|
|
serial.writeLine("Hello!");
|
2016-04-05 22:23:42 +02:00
|
|
|
control.inBackground(() => {});
|
2016-03-26 00:47:20 +01:00
|
|
|
```
|
|
|
|
|
2016-04-05 22:23:42 +02:00
|
|
|
## Language
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-04-05 22:23:42 +02:00
|
|
|
### @section full
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-04-05 22:23:42 +02:00
|
|
|
### ~column
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
### Loops
|
|
|
|
|
|
|
|
[for](/microbit/reference/loops/for)
|
|
|
|
|
|
|
|
```block
|
|
|
|
for(let i = 0;i<5;i++) {}
|
|
|
|
```
|
|
|
|
|
|
|
|
[repeat](/microbit/reference/loops/repeat)
|
|
|
|
|
|
|
|
![](/static/mb/blocks/contents-0.png)
|
|
|
|
|
|
|
|
[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;
|
|
|
|
```
|
2016-04-05 22:23:42 +02:00
|
|
|
### ~
|
|
|
|
|
|
|
|
### ~column
|
|
|
|
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
### 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);
|
|
|
|
```
|
|
|
|
### Comments
|
|
|
|
|
|
|
|
[comment](/microbit/reference/comment)
|
|
|
|
|
|
|
|
### ~
|