pxt-calliope/docs/reference.md
Peli de Halleux cdd4798945 namspace docs
2016-04-05 13:23:42 -07:00

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

for(let i = 0;i<5;i++) {}

repeat

while

while(true) {}

forever

basic.forever(() => {})

~

~column

Logic

if

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);

Comments

comment

~