#include <Arduino_FreeRTOS.h>
void setup() {
Serial.begin(9600);
//if the Priority is higher, it will be the first task to be prioritize
//which Task 2 will go first then Task 1
//but if its the same Priority, then they will go at the same time
xTaskCreate(task1, "print_task1", 128, NULL, 2, NULL);
xTaskCreate(task2, "print_task2", 128, NULL, 2, NULL);
}
void loop() {
//this part of the code is empty
}
void task1(void *pv){
//How you normally call a code/delay a code
//for(;;){
// Serial.println("Hello from Task!");
// delay(1000);
//}
//Another method of delay using 'vTaskDelay'
while(1){
Serial.println("Hello from task1!");
vTaskDelay(1000/portTICK_PERIOD_MS);
}
}
void task2(void *pv){
while(1){
Serial.println("Hello from task2!");
vTaskDelay(1000/portTICK_PERIOD_MS);
//Blocking Delay, it will proceed after the time is up
my_delay(1000);
}
}
//using block delay function
void my_delay(uint32_t t){
uint32_t t1 = millis();
uint32_t t2 = millis();
while((t2-t1) < t){
t2 = millis();
}
}