// GPIO LED
#define RedLEDPin 4
#define GreenLEDPin 14
// Using 2 diferent Task Functions, one for each LED
void blinkRedLED(void *arg) {
pinMode(RedLEDPin, OUTPUT);
while (1) {
digitalWrite(RedLEDPin, HIGH);
delay(300);
digitalWrite(RedLEDPin, LOW);
delay(300);
}
}
void blinkGreenLED(void *arg) {
pinMode(GreenLEDPin, OUTPUT);
while (1) {
digitalWrite(GreenLEDPin, HIGH);
delay(200);
digitalWrite(GreenLEDPin, LOW);
delay(200);
}
}
void setup() {
Serial.begin(115200);
// Two Tasks, each one with a different function task
xTaskCreate(
blinkRedLED // Specific Red LED C Function
, "Red Blink" // A name just for humans
, 2048 // The stack size
, NULL // Task parameter - NONE - all info in the Task Function
, 2 // Priority
, NULL // Task handle is not used here - simply pass NULL
);
xTaskCreate(
blinkGreenLED // Specific Green LED C Function
, "Green Blink" // A name just for humans
, 2048 // The stack size
, NULL // Task parameter - NONE - all info in the Task Function
, 2 // Priority
, NULL // Task handle is not used here - simply pass NULL
);
}
void loop() {
// When using Task, loop() is free for any other need.
// Blinking the LED is done in the Task Function
Serial.println("Looping...");
delay(5000);
}