Smart tiles do not need to work with data to any great extent. They are designed to do things rather than to know things. Data is limited to flags, counting, and other ways of tracking the item's overall behavior, and the states of its neighbors. These activities can be supported using a very limited set of data types and operations.

The tiles visually express themselves by illuminating their surfaces with one of four "colors": OFF, AMBER, GREEN, and RED, and OFF. Each color is preceded by the verb TURN. (ie. TURN RED)
image showing the text programming GUI, showing a rule description in Logo Each cube executes a bytecode interpreter which understands a homegrown dialect of Logo tailored to the expressive needs of a smart cube.

The language supports querying for number of neighbors of particular colors, if the cube was recently tapped, and which of three colors to "become". Each byte code is an 8-bit number between 0 and 255, programmed into the microcontroller's on-board EEPROM. Most of them correspond directly to a Cube Logo primitive like RED, OFF, GREEN, etc. A few of them are special opcodes used to flag some of the subsequent bytes as something other than a usual byte code.

Mathematical operation is limited to binary addition (+), subtraction (-), and assignment (=). Logical operations are limited to AND (&&), and OR (||). Comparative binary operations (==, !=, >, <, >=, and <=) are also supported.

In addition to conditional expressions, the language provides a boolean (read-only) variable TAPPED which returns TRUE if the cube was recently tapped.

There are 4 general purpose variables: A, B, C, and D. 5 read-only variables OFF, ON, RED, GREEN, and AMBER contain the current color (state) of a cube. The read-only variables ON-NEIGHBORS, RED-NEIGHBORS, GREEN-NEIGHBORS, and AMBER-NEIGHBORS indicate how many tiles in a specified neighborhood (MOORE or VON NEUMANN) exhibit those particular colors. The NEIGHBORS keyword reports the number of neighbors that are currently not OFF.

The language also supports primitives for pausing program execution and for generating random numbers: WAIT pauses code execution for tenths of a second and can take variables, expressions, and constants as arguments. RANDOM generates pseudo random integers between zero and one less than the argument value.

Conditional operations use an IF, IFELSE, or WHEN construct. The IFELSE construct allows for only two code blocks, the first executed if the condition was true, the second otherwise. Although the language does not support the multiple IF - ELSEIF - ELSE constructs available in more conventional languages, the conditional operations can be nested to arbitrary depths to achieve the same effect. The WHEN operation will execute a block of code when an externally caused change occurs.

Iteration is provided by the infinite LOOP, and the REPEAT keyword which will execute a block of code for a specified number of times; the repeat value can be an expression, variable or a constant.

All of the control and iterative structures assume a code block surrounded by a pair of opening and ending braces '[', ']'. This minimizes the different ways to write code for a block and eliminates the dangling else problem, though it does require a pair of braces even when the block is a single statement. There is no support for grouping statements into different functions, nor for making function calls -- in essence the language only allows for a single, unnamed Logo procedure.




Craft Technology Group    Howtos    Projects    Publications    Research    Not-a-Blog    Contact