States

Your code runs in one state at a time.  The state runs repeatedly until the state times out or you switch to a new state.

If a time is entered in the "Run Time" box, the state will run only for that length of time before switching to the next state. Time is in milliseconds (1000 = 1 second).

state = "turnLeft"
Switches to your state named turnLeft.

delay(1000)
Pauses running the code for 1000 milliseconds (1 second) while the robot continues to follow the previous instruction.

stop()
Stops running the code, exiting your states.



Basic User Interface (UI)

print("string")
String will appear to the right side of the state in the code editor.

label("string")
String will appear in the UI window. This is useful for explaining things to the user.

button("Lefty!", "turnLeft")
Creates a button in the UI panel called Lefty!. Pressing this button will run the state named turnLeft.

checkbox("string")
Creates a checkbox called string. The value of the checkbox is true or false depending on whether it is checked or unchecked, so it can be used as a condition in an "if" statement: if (checkbox("string")) ...

checkbox("string", "store.v")
If the box is checked, the value of store.v is set to true. If the box is unchecked, it is set to false.

power.L=slider("Left", -100, 0, 100)
Creates a slider in the UI to control the left wheel, with range -100 to 100, and the slider first set to 0.


Create2 Driving

forward(10)
Drive forward 10 centimeters.

backward(5)
Drive backward 5 centimeters.

left(45) 
Turn left 45 degrees.

right(90)
Turn right 90 degrees.

drive(-5, 20)
Sets the speed of the left wheel to -5 and the speed of the right wheel to +20 (range is -100 to 100).

driveToPoint(3, -2)
Turn toward the point on the map given by cartesian coordinates (3, -2), 3 meters to the right and 2 meters down, and drive forward until that point is reached.

Servos

power.servo[0] = 90
Moves the first servo to position 90 degrees (range is 0 to 180 degrees)


PWM (Pulse Width Modulation)

power.pwm[0] = 100
Sets the value of the first PWM to 100, full power (range is 0 to 100).


Neopixel LEDs

power.neopixel[0].color = {r:20,g:0,b:0}
Sets all the neopixels to a dim red color.

power.neopixel[0].color = {
	r:slider("Red",0,10,100),
	g:slider("Green",0,10,100),
	b:slider("Blue",0,10,100)
}
Adds sliders in the UI panel to control the neopixel colors.

power.neopixel[0].color = {r:10,g:10,b:10}
power.neopixel[0].accent = {r:100,g:0,b:0}
power.neopixel[0].repeat = 4
power.neopixel[0].start = time/250
Animates a bright red accent on a dim white background.

Variables

store.x = 20.0 
store.x = "String"
store.x = store.y
Stores a variable named x and sets it to a number, a string, or the value of another stored variable.

Control Flow

if (expression)
{
	statement1
}
else
{
	statement2
}
If expression evaluates to true, executes statement1, otherwise executes statement2.


Examples: