In this project, we show a simple Weather Application, using ESP32 and OLED. A simple OLed display shows the current temperature and the humidity using the DHT11 sensro and thean attached button works as the user interaction to the application.
- Button Click: Change temperature representation
- Button Clicks: Show Simple Animation
- Seconds Click: Turn monitor off/on
To implement button on_click
the GPIO_INTR_POSEDGE was used to interrupt on up edge of the click, as wrote in lib/button/button.c
. In the hardware, we have a Push Button
with 10K pull down resistor (Using 2 20K parallel), so when the button is pressed, the MCU gets a HIGH voltage.
The Main
application polls the button to see if the flag was changed in order to debounce it and call the on_click
function.
The animation is implemented using "tick". Every call by the main proccess updates the animation accordingly to the current time. This could be used to update an 2D Physics engine and use sprites to update the display.
The main file controls the application flow. We have 2 "Threads": The main
thread polls button values, ticks the animation and show DHT11 informations in
the OLed Screen; The weather
Thread, runs at every 500ms reading from DHT11 hardware and assign the values to a common variable, so the main
thread can read it and show in the display.
On 3 Seconds click the screen is turn off to save battery life, turning on again when pressed for three seconds.