CircuitBlocks Tutorial #2 – Types of Blocks
There are a total of nine block types in CB. Each of them is represented by their own 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() function will run only once. It is primarily used for starting the software, initializing and declaring variables and running 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 over and over again (speed depends on the device – just imagine it’s ultra-fast!).
It should pretty much follow the refresh rate of the screen 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 that have elliptical shape return either integer or float values.
When ever you find circular “holes” inside some blocks, that is the place where variables can be inserted. It’s most commonly found in comparison or action blocks.
Boolean variables are represented by triangular blocks.
Both variables (true and false), as well as functions that return boolean values, have the same shape.
Regardless of color, each of these blocks returns either true or false.
Triangular “holes” require boolean blocks to be inserted.
Everything else is basically a building block. Those are functions that have no return value (they return null). Both elliptical and triangular blocks first have to be placed inside of the building blocks in order to act as part of the program.
They have a specific “puzzle” shape and can be stacked inside each other.
The main building block is located inside the ‘Functions’ section.
It basically gives you two main building blocks sections.
Everything that is placed inside Arduino run first goes into void setup() and everything that
is placed inside Arduino loop forever goes into void loop().
Now, this is the main part.
The whole point of blocks-like IDE is connecting blocks and placing
them one 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.
This is where the base of every code is located.
Every if, if-else, else function, as well as comparisons, and/or, not, true/false and other logical operators.
Loops are functions that repeat everything inside for a specific amount of times.
They can either have conditionals, and repeat for as long as that conditions is met, or they can have pre-determined amount of repeats.
Pretty much every math function is located here. From basic operations to rounding numbers and working with angles, you will easily trigger your inner Einstein or Pythagora in a matter of seconds!
Strings, characters and string manipulation. Great place for creating new text and implementing it to your programs.
Create a variable of any type and set its name and desired value. CB will automatically recognize the type of the variable (int, double, string, boolean) so you don’t need to worry about that.
Default Arduino function (which is explained above) is located here.
You can also create your own functions which can then be inserted as one of the main parts of your program.
Everything regarding Ringo’s components is located here.
LEDs, buttons and joystick is controlled via these blocks.
Well, all these blocks are really not important if you don’t see anything on the screen!
Here is where all the magic translates to those colored pixels. You can create so much through these blocks.
Delays, timers and other time-related stuff, great for creating cool animations and video games.
There is also a search bar above all function sections to ease the search for that one specific block you just can’t seem to find (where is that PRINT???).
Just type in whatever comes to your mind and all blocks that have anything to do with the written word will be shown on the right-hand side.
Now, you really can’t say that it’s impossible to find something.
You’ve learned everything about the blocks!
It’s time to move on to the next lesson…