1. How often (I mean how many times per sec) you wish to read the analog input?
2. What are the On-time (for how long the LED remains On) and Off-time (for how long the LED remains Off) of your blinking LED?
3. It is seen from your sketch of Post #1 that you are acquiring input signal at at every 1200 ms (200 + 500 + 500) interval. Your LED is turned On at every 1200 ms interval and remains On for 500 ms. The LED is turned Off at every 1200 ms interval and remains Off for 500 ms. This is a process of sequentila operation whose timing diagram is given below (Fig-1).
Figure-1:
4. You want to feel that the two tasks (ADC acquisition at 200 ms interval) and LED blinking at 1-sec interval should happen concurrently/simultaneously. The tming diagram would be something like Fig-2. (Note that the tasks are asynchronous though timing lines are aligned.)
Figure-2:
5. There is only one processor in your MCU which must execute tasks one-after-another in a sequential manner. How can it perform tasks simultaneously when it (the MCU) is a Serial Device? It can't; but, there is mechanism to do do it; where, the eyes are hyptonized to believe that the tasks are being executed concurrently (untrue parallelism.)
6. Many ways have been prescribed in the previous posts to blink the LEDs concurrently. I wish to do it using FreeRTOS Library that is supported by ESP32 and UNOR4.
.... pending
7. Example: Blinking three LEDs concurrently using FreeRTOS Library. This sketch can be modified for "two LEDs" or "two LED + one ADC channe (Fig-3)".
Schematic:
Figure-1:
Timing Diagram:
Figure-2:
Sketch:
//function declarations
TaskHandle_t Task10Handle;
TaskHandle_t Task11Handle;
//GPIO definitions
#define LED 2
#define LED10 21
#define LED11 22
//task creation using FreeRTOS.h Librray functions
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(LED10, OUTPUT);
pinMode(LED11, OUTPUT);
xTaskCreatePinnedToCore(Task10, "Task-10", 2048, NULL, 2, &Task10Handle, 1);
xTaskCreatePinnedToCore(Task11, "Task-11", 2048, NULL, 3, &Task10Handle, 1);
}
//LED blinks at 2000 ms interval
void loop()
{
digitalWrite(LED, HIGH);
vTaskDelay(pdMS_TO_TICKS(2000)); // Delay the task for 100 milliseconds
digitalWrite(LED, LOW);
vTaskDelay(pdMS_TO_TICKS(2000));
}
//LED10 blins at 1000 ms interval
void Task10(void *pvParameters)
{
while (true)
{
digitalWrite(LED10, HIGH);
vTaskDelay(pdMS_TO_TICKS(1000)); // Delay the task for 1000 milliseconds
digitalWrite(LED10, LOW);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
//LED11 blinks at 500 ms interval
void Task11(void *pvParameters)
{
while (true)
{
digitalWrite(LED11, HIGH);
vTaskDelay(pdMS_TO_TICKS(500)); // Delay the task for 500 milliseconds
digitalWrite(LED11, LOW);
vTaskDelay(pdMS_TO_TICKS(500));
}
}
8. Upload sketch of Step-7 and observe that the three LEDs are blinking concurrentlt at their respective intervals.
9. Eexrcise: Blinking Two LEDs and one ADC channel acquisition concurrently.
Figure-3: