Cricket Logo Command Reference

Motors

a, selects motor A to be controlled.
b, selects motor B to be controlled.
ab, selects motors A and B to be controlled.
c, selects motor C to be controlled.
d, selects motor D to be controlled.
cd, selects motors C and D to be controlled.
abcd, selects all motors to be controlled.
on turns the selected motors on.
off turns the selected motors off.
brake actively applies a brake to the selected motors.
onfor duration turns the selected motors on for a duration of time, where duration is given in tenths-of- seconds. E.g., onfor 10 turns the selected motors on for one second.
thisway sets the selected motors to go the "thisway" direction, which is defined as the way that makes the indicator LEDs light up green.
thatway sets the selected motors to go the "thatway" direction, which is defined as the way that makes the indicator LEDs light up red.
rd reverses the direction of the selected motors. Whichever way they were going, they will go the opposite way.
setpower level sets the selected motor(s) power level. Input is in the range of 0 (coasting with no power) to 8 (full power).

Servo Motors

setsvh direction sets the servo heading. direction for a typical servo motor should range between 15-45.
svr steps turns right (counter clock wise) for a number of steps.
svl steps turns left (clock wise) for a number of steps.

Timing

timer reports value of free-running elapsed time device.
Time units are reported in 1 millisecond counts.
resett resets elapsed time counter to zero.
wait duration delays for a duration of time, where duration is given in tenths-of-seconds. E.g., wait 10 inserts a delay of one second.

Sound

beep plays a short beep.

Sensors and Data Collecting

sensor1 reports the value of sensor 1, as a number from 0 to 1023.
sensor2 reports the value of sensor 2, as a number from 0 to 1023.
sensor3
sensor4
sensor5
sensor6
sensor7
sensor8
same as sensor1 and sensor2, but report values of the corresponding sensor.
switch1 reports "true" if the switch plugged into sensor A is pressed, and "false" if not.
switch2 reports "true" if the switch plugged into sensor B is pressed, and "false" if not.
switch3
switch4
switch5
switch6
switch7
switch8
same as switch1 and switch2, but report values of the corresponding sensor.
resetdp reset the value of data pointer to 0.
record value records value in the data buffer and advances the data pointer.
recall value reports the value of the current data point and advances the data pointer.
erase number sets the value of the first number elements of the data array to zero and then sets the data pointer to zero. Because the process of recording data is relatively slow (about 20 milliseconds per data point) it could take as long as 50 seconds for the erase 2500 command to be executed.

Control

forever [body] repetitively executes body indefinitely.
repeat times [body] executes body for times repetitions. times may be a constant or a calculated value.
if condition [body] if condition is true, the cricket executes body. Note: a condition expression that evaluates to zero is considered "false"; all non-zero expressions are "true".
ifelse condition [body1] [body2] if condition is true, executes body-1; otherwise, executes body-2.
waituntil [condition] loops repeatedly testing condition, continuing subsequent program execution after it becomes true. Note that condition must be contained in square brackets; this is unlike the conditions for if and ifelse, which do not use brackets.
stop terminates execution of procedure, returning control to calling procedure.
output value terminates execution of procedure, reporting value as result.

Numbers

+ infix addition
- infix subtraction
* infix multiplication
/ infix division
% infix modulus (remainder after integer division)
and infix logical "and" operation (bitwise and)
or infix logical "or" operation (bitwise or)
xor infix logical "xor" operation (bitwise xor)
not prefix logical not operation. use only with boolean values (1 and 0).
random reports pseudo-random number from 0 to 32767.

Globals and Arrays

make "foo 10

 

wait :foo

 

 

make "foo :foo + 1

creates a global variable named foo and set its value to 10

variable values are accessed by adding a colon (:) in front of the variable name. If foo in the wait example contains 10 then the command will wait for 1 second



an example that increases the value of foo by one

 

array [array1-name, array1-length, array2-name, array2-length, etc.] creates two arrays, one named foo, which can hold 50 numbers and another named bar, which can hold 25 numbers. Elements in the array are set and read using the aset and aget primitives:
aset array-name item-number value sets the item-numberth element of array-name to value
aget array-name item-number reports the item-numberth element of array-name

Serial Communication

send value transmits value via Com port.
serial reports the byte most recently received by the serial port.
newserial? reports true if a new byte has been received by the serial port since last time serial was used, and false if not. It does not effect the content of the serial buffer.