This is the first of a series of blog posts about the new feature and updates to the Blocktinu.
The Scheduler allows you to execute pieces of your code in equal intervals of time. This is designed, of course, for the Tinusaur boards but will work on almost any ATtiny85 configuration.
You still must supply the infinite repeat as the main program because otherwise, the execution will halt almost immediately.
It works like this: the main program runs as usual, but each time a timer ticks the execution of the main program will be interrupted and the scheduled piece of code will be executed. After it finishes, the main program resumes its execution.
For the implementation of this functionality, we use the Scheduler library from the TinyAVRLib project
- Library page: https://tinusaur.com/libraries/tinyavrlib/
- Source code: https://gitlab.com/tinusaur/tinyavrlib at GitLab
Mirror at Github: https://github.com/tinusaur/tinyavrlib
The Blocktinu Schedule module has at the moment only 1 block called “Scheduler” that has only 1 parameter – “Counter”. The Scheduler block will tick every 10 milliseconds and if the counter is “0” it will execute the code between the brackets. If not, it will decrease the value of the counter every 10 milliseconds and when it reaches “0” it will execute the code between the brackets.
The “Counter” accepts values between 0 and 65535 which means you could specify intervals between 10 milliseconds and 655.35 seconds (a little over 10 minutes).
You MUST NOT have more than one Scheduler block otherwise the result might be unpredictable.
Here is an example: the main program makes one of the LEDs blink while the Schedule makes the other LED blink.
IMPORTANT: Make sure that the code within the Scheduler brackets does not take time more than the time between 2 ticks. If it overlaps the results might be unpredictable.
For the same reason, it is not recommended to use Delay blocks for “measuring” the time in a code that is in the Scheduler’s brackets.
Please, experiment with the Scheduler block and give us feedback.