CODE

Key Concepts

Here are some basic Cubelets CODE concepts you need to know.

Block Value

One of the first things to know when using Cubelets CODE is the concept of a block value. Every Cubelet has a block value—simply a number that ranges from 0 to 255. The block value of a Sense Cubelet is based on its sensor. For example, in a really bright room, a Brightness Cubelet will have a block value of 255. If it's really dark, its block value will be close to zero. Action blocks use their block values to operate their actuators. With a block value of 255, a Drive Cubelet drives at maximum speed. For a Flashlight Cubelet, a block value of 255 lights the flashlight at its brightest.

Sense, Think, Act

Think of a robot as a being that thinks, senses, and acts (that's why we have Sense Cubelets, Think Cubelets, and Action Cubelets). Each individual Cubelet performs at least one of these functions. When we reprogram Cubelets, you will see that the programs you write always follow this pattern.

setup() and loop()

Your code to reprogram a Cubelet will contain (at least) a setup () function to start the block when it's first turned on, and a loop() function to tell it what to do when it's running. (It may contain other routines also, but that's another story). Setup happens just once when you first power on your robot. The loop function is called over and over again while your robot is powered on. More on this later.

Cubelets API

To make programming your Cubelets easier, we have created an application programmer interface (API ) for some of the most common tasks you will want to accomplish. We will discuss some of the API functions later, but for a sneak peek at what the API offers, please see the API reference.


Next

In order to start using CODE, let's walk through its user interface.


Continue to Navigating CODE.