lcd I2c backlight control

Thread Starter

mihaita212

Joined Mar 26, 2017
10
Hello guys i want to control the lcd backlight with a push button when i press the button the backlight stays on for 30 sec then it turn of.I'm using a LCD1602 display with an i2c module
Code:
if (buttonState == LOW) {
  lcd.backlight();
}
else
  lcd.noBacklight();
Something like this but when i take off my finger from the button the lcd backlight turns off , i want to stay on for 30 sec then turn off.
PS: i don't want to use delay function
 

Thread Starter

mihaita212

Joined Mar 26, 2017
10
figuere it out , if someone need the same thing :
Code:
if (buttonState == LOW) {
    lcd.clear();
    lcdLightOn_StartMillis = millis();
    currentLcdLightOnTime = 0;
    isLcdLightOn = true;
    lcd.backlight();
  }
    if(isLcdLightOn){
      currentLcdLightOnTime = millis() - lcdLightOn_StartMillis;
      if(currentLcdLightOnTime > LCD_LIGHT_ON_TIME){
        isLcdLightOn = false;
        lcd.noBacklight();
      }
    }
 
Top