1 /* Blink without Delay: RTOS
3 Implementazione di due processi indipendenti:
4 TaskFirstBlink e TaskSecondBlink
5 per far lampeggiare due LED tramite il framework FreeRTOS
7 * E' necessario installare la libreria: Arduino_FreeRTOS
8 - https://github.com/feilipu/Arduino_FreeRTOS_Library
9 - https://www.hackster.io/feilipu/using-freertos-multi-tasking-in-arduino-ebc3cc
11 #include <Arduino_FreeRTOS.h>
13 // define two tasks for Blink & AnalogRead
14 void TaskFirstBlink( void *pvParameters );
15 void TaskSecondBlink( void *pvParameters );
17 // the setup function runs once when you press reset or power the board
20 // Now set up two tasks to run independently.
23 , (const portCHAR *)"First Blink" // A name just for humans
24 , 128 // This stack size can be checked & adjusted by reading the Stack Highwater
26 , 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
31 , (const portCHAR *) "Sec Blink"
37 // Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started.
42 // Empty. Things are done in Tasks.
46 This example code is in the public domain.
58 /*--------------------------------------------------*/
59 /*---------------------- Tasks ---------------------*/
60 /*--------------------------------------------------*/
63 void TaskFirstBlink(void *pvParameters) // This is a task.
67 // initialize digital LED_BUILTIN on pin 13 as an output.
69 const int pausa = 500;
72 for (;;) // Equivalent to the classic loop() function
74 digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
75 vTaskDelay( pausa / portTICK_PERIOD_MS ); // wait for one second
76 digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
77 vTaskDelay( pausa / portTICK_PERIOD_MS ); // wait for one second
82 void TaskSecondBlink(void *pvParameters) // This is a task.
87 const int pausa = 1000;
92 digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level)
93 vTaskDelay( pausa / portTICK_PERIOD_MS ); // wait for one second
94 digitalWrite(3, LOW); // turn the LED off by making the voltage LOW
95 vTaskDelay( pausa / portTICK_PERIOD_MS ); // wait for one second