Types of blocks
There are a total of nine block types in CB. Each of them is represented by their color. Every block translates to code, which is then compiled and uploaded to the phone, just like on every Arduino based platform.
Pressing on every block type will open a section from which you can drag and drop those blocks into the drawing area.
Also, pressing on ‘More’ will open even more blocks that are not so commonly used.
There are two main functions of every Arduino code – void setup() and void loop().
Everything that goes into the void setup() the function will run only once. It is primarily used to start the software, initialize and declare variables, and run functions that only have to run once (ex., Intro screen in a video game).
The void loop() is where everything else takes place. It basically runs every bit of code inside it repeatedly (speed depends on the device – just imagine it’s ultra-fast!). It should pretty much follow the screen's refresh rate and make the program do things accordingly.
Every block you place automatically goes into the void loop() function.
If you wish to put something in the void setup(), you have to drag the main block from Functions and place your blocks inside as you wish, but more on that a little bit later.
Elliptical blocks represent variables. Whether we’re talking about integers, strings, or other variable types (other than Boolean), they can all be recognized by the same shape.
Also, larger blocks with elliptical shapes return either integer or float values.
Triangular blocks represent boolean variables.
Both variables (true and false) and functions that return boolean values have the same shape.
It basically gives you two main building blocks sections.
Everything placed inside Arduino runs first goes into void setup(), and everything placed inside Arduino loop forever goes into a void loop().
The whole point of blocks-like IDE is connecting blocks and placing them inside another.
It is all done by simple drag-and-drop action.
Here is an example of a program that will set the variable Var to 1 and then increase that variable while it is smaller than 10.
At the end of the program, Var will be 10.
This is just a simple example, and block-building will be further explained in the following chapters.