65.9K
CodeProject 正在变化。 阅读更多。
Home

使用 LCD Miser 节省您的物联网设备电池

starIconstarIconstarIconstarIconstarIcon

5.00/5 (5投票s)

2022 年 7 月 21 日

MIT

1分钟阅读

viewsIcon

5666

downloadIcon

67

轻松在超时后关闭屏幕

引言

在物联网领域,电池寿命至关重要。如果设备需要每隔几个小时充电一次,这些小工具就毫无用处了。因此,大多数物联网设备都有有时很复杂的省电方案,但却没有内置机制来解决最大的耗电大户之一——您的屏幕背光。

这时,LCD Miser 就派上用场了。这是一个易于使用的 Platform IO 库(尽管它可以复制到 Arduino IDE 的库中),它接管您的屏幕背光并提供超时功能。

在 ESP32 上,它会像智能手机一样逐渐变暗。在其他平台上,它会直接关闭。

Using the Code

使用代码很简单

lcd_miser<PIN_NUM_BCKL,BCKL_HIGH> lcd_power;
...
void setup() {
  Serial.begin(115200);
  // Must initialize the class
  lcd_power.initialize();
  // uncomment to change the timeout
  // to 10 seconds
  //lcd_power.timeout(10000);
  // set up the button callback
  button0.callback([](bool pressed,void* state) 
    {lcd_power.wake();});
  // fill the screen
  lcd.fill(lcd.bounds(),color_t::white);

}

void loop() {
  // IMPORTANT: You must always
  // pump the lcd_power so it can
  // have a chance to time out
  lcd_power.update();
  // ensure button callbacks
  // get fired
  button0.update();
}

这个例子使用了 htcw_gfxhtcw_button 来完成大部分与屏幕背光无关的繁重工作。 您可以看到您只需要 initialize()update()wake()。 调用 wake() 会重置计时器,因此您可以继续调用它以防止屏幕关闭。

需要注意的是,您应该告诉您使用的图形库您的显示屏上没有背光,通常是通过将引脚分配设置为 -1。 这样,您就不会有两个东西争夺同一个引脚,这可能会导致问题。

您可以通过在 platformio.ini 中添加以下内容来将此包含在您的项目中

lib_ldf_mode = deep
lib_deps = 
    codewitch-honey-crisis/htcw_lcd_miser

历史

  • 2022 年 7 月 21 日 - 首次提交
© . All rights reserved.