CODE
Variables
Globals
Globals are variables that can be used anywhere in your code.
block_type
A global variable that contains the type of the Cubelet currently running the program. Can be compared to any of the Cubelet Types listed below.
block_value
Each Cubelet has a block_value, a number 0-255. This number is what determines most blocks behavior. For example, a Drive Cubelet with a block_value of 255 will drive at full speed; if there is an object really close to a Distance Cubelet, it's block value will be close to 255, if there is no object, it's block_value will be 0.
neighbor_data
An immutable object containing information about a Cubelets neighbors. Most Cubelets use neighbor_data when calculating their block_value. At present, neighbor_data is a private object whose data cannot be accessed.
Constants
Constants are variables that can be accessed anywhere in your code, but cannot be modified.
BACKWARD
A constant useful for setting the direction of a motor in a Drive Cubelet or a Rotate Cubelet.
FORWARD
A constant useful for setting the direction of a motor in a Drive Cubelet or a Rotate Cubelet.
Cubelet Types
Cubelet Types are global constants that can be used to programmatically determine the type of a Cubelet.
BAR_GRAPH_CUBELET
BATTERY_CUBELET
BLOCKER_CUBELET
BRIGHTNESS_CUBELET
DISTANCE_CUBELET
DRIVE_CUBELET
FLASHLIGHT_CUBELET
INVERSE_CUBELET
KNOB_CUBELET
MAXIMUM_CUBELET
MINIMUM_CUBELET
PASSIVE_CUBELET
ROTATE_CUBELET
SPEAKER_CUBELET
TEMPERATURE_CUBELET
  1. void setup()
  2. {
  3. }
  4. void loop()
  5. {
  6. think();
  7. }
  8. void think()
  9. {
  10. switch(block_type)
  11. {
  12. case MINIMUM_CUBELET:
  13. block_value = minimum(neighbor_data);
  14. break;
  15. case MAXIMUM_CUBELET:
  16. block_value = maximum(neighbor_data);
  17. break;
  18. case INVERSE_CUBELET:
  19. block_value = weighted_average(neighbor_data);
  20. block_value = inverse(block_value);
  21. break;
  22. case PASSIVE_CUBELET:
  23. block_value = weighted_average(neighbor_data);
  24. break;
  25. default:
  26. break;
  27. }
  28. }