1.8 KiB
1.8 KiB
Reference
micro:bit
basic.showString("Hello!");
input.onButtonPressed(Button.A, () => {});
led.plot(0,0);
radio.sendNumber(0);
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Whole));
game.createSprite();
pins.digitalReadPin(DigitalPin.P0);
serial.WriteLine("Hello!")
control.inBackground(() => {});
Language
@section full
~column
Loops
for(let i = 0;i<5;i++) {}
while(true) {}
basic.forever(() => {})
~
~column
Logic
if(false) {
}
Boolean values: true; false
true
false
Boolean binary operators: and (conjunction); or (disjunction)
true && false;
true || false;
Boolean negation operator
!true
Comparison operators (=, !=, <, >, <=, >=)
0 == 0;
1 !- 0;
0 < 1;
1 > 0;
0 <= 1;
1 >= 0;
Variables
Assign (set) a variable's value
let x = 0;
Get a variable's value
let x = 0;
x;
Change a variable's value
let x = 0;
x+=1;
~
~column
Math
Numeric values: 0, 1, 2, ...
0;
1;
2;
Arithmetic binary operation (+, -, *, /)
0+1;
0-1;
1*2;
3/4;
Absolute value
Math.abs(-5);
Minimum/maximum of two values
Math.min(0, 1);
Math.max(0, 1);
Random value
Math.random(5);