Clock Library
This example uses clocks and illustrates a radically different approach from the example provided on the MSP432 review. Both examples do exactly the same: they blink each colour of the RGB LED at different speeds.
The preliminary part of the sketch is very standard, with includes, a structure for the LED, variables for each colour of the RGB LED, and functions for each colour of the RGB LED.
|
|
Instead of having 3 tasks, the main part of the sketch contains three clocks. Each clock calls a dedicated function to manage one colour of the RGB LED.
The function called by the Clock needs to be void clockFunction(). Two periods are defined:
Both are stated in ms. If the initial start delay is equal to 0, the clock starts immediately. If the repetitive period is equal to 0, the clock runs only once (one-shot timer). In this example, the clocks start running after 1 second, and call the respective functions every 100, 333 or 500 ms. Note the function loop() is empty. Everything is managed by SYS/BIOS, the OS of TI-RTOS used by Energia MT. |
|
Now, compare this implementation with the sketch commented on the MSP432 review. Both do the same. Which one do you prefer?
|