I have an LCD using I2C. I have the text turning on and off every 1.5 seconds or so. I wanted to connect a momentary button that would toggle the backlight when pressed and keep it on for 3 seconds after being pressed and then shut off again. I want this to be independent of the message turning on and off on the screen.
I have read through the blink without delay stuff hoping it would help me but I don't know how to incorporate a button in that context, if that's even remotely close to what I should be thinking. I just started w arduino so I'm clueless. Here is my code. I know it's not going to work correctly this way but I just don't know how to fix it.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
/**********************************************************/
// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
const int buttonPin = 2;
int buttonState = 0;
/*********************************************************/
void setup()
{
lcd.init(); //initialize the lcd
//lcd.backlight(); //open the backlight
pinMode(buttonPin, INPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
lcd.backlight();
delay(3000);
}
else{
lcd.noBacklight();
}
lcd.setCursor(3,0);
lcd.print("Welcome To");
lcd.setCursor(4,1);
lcd.print("Room 222");
delay(1500);
lcd.clear();
delay(1200);
}