This is an old revision of the document!
It is advised to use timers that periodically execute a function to handle repeating tasks. Hardware timers work parallel to the CPU and consume few CPU resources. ESP32-S3 has 4 hardware timers, but each timer can execute multiple handlers.
The idea of using the timer is to encapsulate a piece of compact code that can be run virtually asynchronously and executed is a precisely-defined time manner. In this scenario, we use a timer to update the LCD screen periodically. We choose a dummy example where Timer 1 is used to increment a value of the byte
type, and Timer 2 reads this value and writes it on the LCD. Naturally, a collision may occur whenever two processes are to access a single memory block (variable). It is critical when both processes (tasks, asynchronous functions) are writing to it. However, in our example, the handler executed by Timer 1 only writes to the variable, while Timer 2 only reads from it. In this scenario, there is no need to use mutexes (semaphores). A scenario with detailed description of when to use mutexes is beyond the scope of this example.
To implement this scenario, it is necessary to get familiar with at least one of the following scenarios first:
A standard LCD handling library is attached to the platformio.ini
, and it is the only library needed. Timers are integrated into the Arduino framework for ESP32.
lib_deps = adafruit/Adafruit LiquidCrystal@^2.0.2
Present on the LCD current value of the byte
variable; update the LCD every 3 seconds using one timer. Use another timer to increase this variable every second.
Write starting conditions, i.e. what to do in the beginning, what to pay attention to before beginning, how the mechanical part should look, etc. Include needed compiler configuration, etc.
Write some extra information if, i.e. some steps are optional; otherwise, cancel this paragraph (but do not remove the header).
Describe activities done in Step 1.
…
Describe activities done in Step n.
On the LCD screen, you should see values starting from number 3, then 6, 9, 12 and so on (=3 every 3 seconds). Note, as byte
has a capacity of 256 (0…255), the sequence changes in the following increments once it overflows.
This section is to be extended as new questions appear.
When using the printed version of this manual, please refer to the latest online version of this document to obtain the valid and up-to-date list of the FAQ.
Provide some FAQs in the following form:
Question?: Answer.