Toggling LCD Backlight with arduino ?

Hey, I'm working on a project where I need my LCD to toggle between On/Off. 
By default, the LCD is OFF showing nothing. When button is pressed, LCD should be ON.
When the button is pressed again, the LCD will display a “shutdown” warning message at which the user can confirm or cancel.
Right now, I just need the ON/OFF function to work (without warning message). This is the code I have been trying, but it doesn't work properly.

#include <LiquidCrystal.h>
#include <SD.h>

const int Temp = 0;
const int Press = 1;     
const int Noise = 2;         
const int Settings = 3;
const int ON_OFF = 8;
const int LCD_LIGHT = A4;

int buttonState0 = 0;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;

bool isLcdOn = false;
LiquidCrystal lcd(12, 11, 4, 5, 6, 7);

void setup() {

  lcd.begin(16, 2);

  pinMode(Settings, INPUT);
  pinMode(Temp, INPUT);
  pinMode(Press, INPUT);
  pinMode(Noise, INPUT);
  pinMode(ON_OFF, INPUT);
  pinMode (LCD_LIGHT, OUTPUT);

void loop() {

  buttonState4 = digitalRead(ON_OFF);

  if (buttonState4 == LOW)
    isLcdOn = !isLcdOn;
      lcd.setCursor(4, 0);
      digitalWrite(LCD_LIGHT, HIGH);
      digitalWrite(LCD_LIGHT, LOW);

steveastrouk3 months ago

Replace your delay with a while (buttonstate4==HIGH) DO; clause.

steveastrouk3 months ago

How "doesn't work properly" ?