Elektor_Mag_-_January-February_2021

([email protected]) #1
lektor January & February 2021 65

host of other, more sophisticated ways to coordinate events using
other FreeRTOS functions.
200528-01

bit for each task. In the loop() function both tasks are notified simul-
taneously by setting their specific event bits at the same time (line 100).


As can be seen, the event group bits can be used to create very
complex and creative application code. For more details on the
additional functions see the book FreeRTOS for ESP32-Arduino [2]
and the FreeRTOS documentation [3].


Running the demo
The demo doesn’t use the Serial Monitor and can be run on just
about any ESP32 that makes GPIO 25 and 26 available (or you can
change lines 5 and 6 of Listing 1 to use different outputs). Flash the
program evtgrp.ino into the ESP32 with two LEDs and 220-ohm
resistors attached according to the schematic in Figure 2. Once
the ESP32 starts execution there should be blinking LEDs — once
per second LED1 should blink twice and then wait while LED2
should blink three times (quickly) and then wait. The process will
repeat every second.


Synchronisation complete
This demo illustrates how two completely independent tasks, blink2()
and blink3(), can be synchronised using a single Event Group object.
The loop() task broadcasts its event from lines 98 to 101. This approach
can be extended to up to 24 tasks if necessary (the limit is defined by
the number of event flags available in a single Event Group). While
this article has shown one way to use Event Groups there are a whole


Contributors
Idea and Text: Warren Gay
Schematic: Patrick Wielders
Image: Jack Jamar

Editor: Stuart Cording
Layout: Giel Dols

Questions or Comments?
Do you have questions or comments about this article?
Email the author at [email protected] or contact Elektor at
[email protected].

related products


> W. Gay, FreeRTOS for ESP32-Arduino, Elektor, 2020.
http://www.elektor.com/freertos-for-esp32-arduino

We connect start-ups with future


customers, partners and resellers.


Learn about the benefits for both


start-ups and investors.


The elektor


investmentprogram


http://www.elektormagazine.com/investment-program


We connect start-ups with future


customers, partners and resellers.


Learn about the benefits for both


start-ups and investors.


investment


http://www.elektormagazine.com/investment-program


Advertisement
Free download pdf