1 #include <Arduino_FreeRTOS.h>
2 /* E' necessario installare la libreria: Arduino_FreeRTOS
3 - https://github.com/feilipu/Arduino_FreeRTOS_Library
4 - https://www.hackster.io/feilipu/using-freertos-multi-tasking-in-arduino-ebc3cc
6 // define two tasks for Blink & AnalogRead
7 void TaskFirstBlink( void *pvParameters );
8 void TaskSecondBlink( void *pvParameters );
10 // the setup function runs once when you press reset or power the board
13 // initialize serial communication at 9600 bits per second:
17 ; // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.
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.
45 /*--------------------------------------------------*/
46 /*---------------------- Tasks ---------------------*/
47 /*--------------------------------------------------*/
49 void TaskFirstBlink(void *pvParameters) // This is a task.
55 Turns on an LED on for one second, then off for one second, repeatedly.
57 Most Arduinos have an on-board LED you can control. On the UNO, LEONARDO, MEGA, and ZERO
58 it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN takes care
59 of use the correct LED pin whatever is the board used.
61 The MICRO does not have a LED_BUILTIN available. For the MICRO board please substitute
62 the LED_BUILTIN definition with either LED_BUILTIN_RX or LED_BUILTIN_TX.
63 e.g. pinMode(LED_BUILTIN_RX, OUTPUT); etc.
65 If you want to know what pin the on-board LED is connected to on your Arduino model, check
66 the Technical Specs of your board at https://www.arduino.cc/en/Main/Products
68 This example code is in the public domain.
77 // initialize digital LED_BUILTIN on pin 13 as an output.
78 pinMode(LED_BUILTIN, OUTPUT);
79 const int pausa = 500;
81 for (;;) // A Task shall never return or exit.
83 digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
84 vTaskDelay( pausa / portTICK_PERIOD_MS ); // wait for one second
85 digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
86 vTaskDelay( pausa / portTICK_PERIOD_MS ); // wait for one second
90 void TaskSecondBlink(void *pvParameters) // This is a task.
95 const int pausa = 1000;
96 for (;;) // A Task shall never return or exit.
98 digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level)
99 vTaskDelay( pausa / portTICK_PERIOD_MS ); // wait for one second
100 digitalWrite(3, LOW); // turn the LED off by making the voltage LOW
101 vTaskDelay( pausa / portTICK_PERIOD_MS ); // wait for one second