Blocktinu is Tinusaur‘s web-based block programming platform for creating programs to be used with our microcontroller boards or similar based on the ATtiny85 microcontroller by Microchip.
Did you know that Blocktinu can be used to create programs not only by using blocks for absolute beginners but also by writing code in the C programming language?
How does this work?
In the current version of Blocktinu (as of February 2023), in the main menu bar at the top, there is a Projects button that leads to a screen with the two projects we can work on. One is with blocks, and the other is in the C language.
Let’s open the one in C.
There is no code in it initially. This is where block programming can come in handy. So let’s go back to the block project and use the Shield EDUx3IO to make a simple button and LED program.
Now is the time to explain how Bloktinu works.
When we arrange blocks on the screen, the platform actually creates C code for us. Blocktinu also gives us the opportunity to peek into the code that has been generated. This is done with the arrow on the far right of the screen.
We can copy the generated C code from the block project to the C code project and use the Build button the same way to compile and upload the program.
If we want to do something more complex in the C language, for example, reading values from the photoresistor, we will have to use the so-called libraries (or software libraries).
Here again, we can resort to the help of block programming by adding a variable x and assigning it the value of the photoresistor.
We immediately notice that several significant changes have occurred in the C code of the block program.
- Added a new line at the beginning of the code:
- Created helper function shield_edux3io_photores().
- Added new lines in the Initialization section.
This code can also be copied into the C project.
An important question at this point is how do the C language libraries work.
They consist of two files – name_of_the_library.h and name_of_the_library.c, and in this case they are:
- tinyavrlib/adcxlib.h – the header file that needs to be included.
- tinyavrlib/adcxlib.c – the source code of the library.
The file “adcxlib.h” contains a description of the library and the functions it implements, while “adcxlib.c” contains the code of those functions themselves.
The ADCxLib library (part of the TinyAVRLib project) helps us work more easily with the so-called analog-digital converters (or ADC) in the ATtiny85 microcontroller.
What Blocktinu does in this case, and which is very convenient for us, is that for the libraries that are installed on the platform, it knows which .h files and which .c files to include in the project.
Another advantage is that we don’t have to install complex and large software packages on our computers in order to program in C. This is because the compilation of our C code is done on Blocktinu‘s servers, where these software packages are already installed.
Blocks or C code?
With Blocktinu, we can create programs with either blocks or in the C language. Which one to choose depends on what we want to achieve, how advanced we are in programming, and how well we know the C programming language.
Creating programs using a programming language like C provides greater opportunities but also requires much more in-depth knowledge of both the language and the hardware platform.
Blocktinu makes it possible to choose between the two depending on the complexity of the problem we are solving and the task we are solving.