One of the biggest battery killers is the backlight on your LCD. Here's a simple to use library which allows it to timeout after a specified period, until it is awoken again.
Introduction
In IoT, battery life is king. These widgets aren't very useful if you have to charge them every other hour. Due to this, most IoT devices have sometimes elaborate power saving schemes, but there's no built in facility for one of the biggest battery killers of them all - your screen's backlight.
Enter LCD Miser. This is a simple to use Platform IO library (although it can be copied into your libraries in the Arduino IDE) that takes over your screen's backlight and provides a timeout.
On the ESP32, it fades just like a smartphone will. On other platforms, it simply blanks.
Using the Code
Using the code is simple:
lcd_miser<PIN_NUM_BCKL,BCKL_HIGH> lcd_power;
...
void setup() {
Serial.begin(115200);
lcd_power.initialize();
button0.callback([](bool pressed,void* state)
{lcd_power.wake();});
lcd.fill(lcd.bounds(),color_t::white);
}
void loop() {
lcd_power.update();
button0.update();
}
This example is using htcw_gfx and htcw_button to do much of the heavy lifting not directly related to the screen's backlight. You can see all you need are initialize()
, update()
and wake()
. Calling wake()
resets the timer so you can keep calling it to prevent the screen from turning off.
One thing to note is you should tell whichever graphics library you use that there is no backlight on your display, usually by setting the pin assignment to -1
. This way, you don't have two things fighting over the same pin, which can cause problems.
You include this in your project by adding this to your platformio.ini:
lib_ldf_mode = deep
lib_deps =
codewitch-honey-crisis/htcw_lcd_miser
History
- 21st July, 2022 - Initial submission