|
Cricket Logo for Blue Dot Crickets |
|
|
| NOTE: A less technical introduction can be found in the document Getting Started With Cricket. |
Cricket Logo has the following features:
procedure-body end When the Cricket is running a program, pressing the start-stop button causes it to halt program execution. |
|
|
| The Cricket has two motors, which are named "A" and "B". A bi-color
LED indicates the state of each motor.
Motor commands are used by first selecting the motor (using a,
, b, , or ab,) and then telling it what to do (e.g., on,
off, rd, etc.).
|
|
|
|
|
The Cricket has two sensors, named "A" and "B".
|
|
|
In addition to the user defined arrays mentioned
above there is a single global array for storing data
which holds 2500 one-byte numbers. There is no error checking to prevent
overrunning the data buffer. The following primitives are available for
data recording and playback:
For example the procedure take-data can be used to store data recorded by a sensor once every second:
erase 2500 beep repeat 2500 [record sensora wait 10] end
resetdp repeat 2500 [send recall wait 5] end |
|
|
Cricket Logo supports the following control structures:
|
|
|
Blue Dot Cricket Logo contains a when primitive that allows for simple
multitasking:
For example, the following program will beep once every second, while reversing the motor direction every tenth of a second:
resett when [timer > 1000] [beep resett] loop [a, onfor 1 rd] end Note: Do not use the stop primitive inside the body of the when command. stop only has meaning inside of a procedure, and the when command executes in its own context, outside of any procedure scope. |
|
|
Cricket Logo supports tail recursion to create infinite loops. For example:
beep wait 1 beep-forever end
loop [beep wait 1] end
beep wait 1 if switcha [beep-when-pressed] end |
|
|
| The "Blue Dot" version of Cricket Logo uses 16-bit integers between
-32768 and + 32767.
All arithmetic operators must be separated by a space on either side.
E.g., the expression 3+4 is not valid. Use 3 + 4.
To perform a bitwise not operation on a 16-bit word value, xor the value with $ffff. |
|
|
Global variables are created using the global [variable-list]
directive at the beginning of the procedures window. E.g.,
|
|
|
Global arrays are created in the Blue Dot version of Cricket Logo using
the
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:
Thus, for example
|
|
|
Procedures can accept arguments using Logoâs colon syntax. E.g.,
ab, repeat :times [on wait 2 rd] end Procedures may return values using the output primitive; e.g.:
ab, repeat third [on wait 10 rd] end to third |
|
|
Crickets can send infrared signals to each other using the send
primitive, and receive them using the ir primitive. The newir?
primitive can be used to check if a new infrared signal has been received
since the last time ir primitive was used.
For example, consider the following use of the newir? primitive: global [temp-ir]In this example nothing happens until a new infrared byte is received. Note the use of global variable temp-ir. The value of the most recent infrared byte is stored in the temp-ir global in order to ensure that the same value is used in testing the conditions for the next two if statements. If we instead use if ir = 1 [thing1] and if ir = 2 [thing2], though unlikely, the content of the ir buffer may change before both conditions are tested. There are cases when you may want to use an alternate form of the thing1-or-thing2 procedure: to thing1-or-thing2In this case we do not wish to hold everything up until a new infrared byte is received; we only want thing1 or thing2 to happen if a new infrared byte is received. |
||||||
There are some subtleties with the inrared codes and the ir primitive
that can lead to confusion:
|
|
|
| Crickets can send commands and data to bus devices using the bsr
and bsend primitives. The bsr is used when the Cricket expects
a response from the device such as a sensor reading from a sensor bus
device. Each bus device has a unique ID. For example, the ID for 4-digit
displays is $70 (the dollar sign indicates that the number is in hex or
base 16). The procedure for displaying a number on the display is: ;the 1 in $170 in the first command indicates
that this is a command and not data. |