pxt-calliope/docs/reference.md
2016-03-25 16:47:20 -07:00

7.4 KiB

Reference

@section full

~column

Basic

show number

basic.showNumber(2)

show string

basic.showString('Hello!')

show LEDs

basic.showLeds(`. . . . . 
. # . # . 
. . . . . 
# . . . # 
. # # # .`)

clear screen

basic.clearScreen()

forever

basic.forever(() => { })

pause

basic.pause(200)

Input

on button pressed

input.onButtonPressed(Button.A, () => {})

on pin pressed

input.onPinPressed(TouchPin.P0, () => {})

on shake

on logo up

on logo down

on screen up

on screen down

button is pressed

compass heading

temperature

acceleration

rotation

magnetic force

running time

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;

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

LED

plot

led.plot(2,2)

unplot

led.unplot(2,2)

point

led.point(2,2)

brightness

led.brightness()

set brightness

led.setBrightness(255)

stop animation

led.stopAnimation()

plot bar graph

led.plotBarGraph(0, 1023)

Game

create sprite

move

turn

change

set

reports

touching

touching edge

if on edge, bounce

change score by

score

start countdown

game over

Music

play tone

ring tone

rest

tempo

set tempo

change tempo

Comments

comment

Images

show image

scroll image

create image

~

~column

Pins

digital read pin

digital write pin

analog read pin

analog write pin

analog set period

servo write pin

servo set pulse

map

Devices

Functions in this category require to be connected to a remote device.

tell camera to

tell remote control to

raise alert to

on notified

on gamepad button

on notified

signal strength

on signal strength changed

~