Hi All.
How would I go about stopping the backlight flashing?
I want the backlight to come on every time the button is pushed to show the status and then go off after a set time without delaying the whole loop.
Code:
Mike.
How would I go about stopping the backlight flashing?
I want the backlight to come on every time the button is pushed to show the status and then go off after a set time without delaying the whole loop.
Code:
C:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
const int buttonPin = 2; // The pin that the pushbutton is attached to
const int valvepin = 1; // The pin that the valves are attached to
// Variables will change:
int buttonState; // Current state of the button
int lastButtonState; // Previous state of the button
bool valveStatus;
void setup()
{
Serial.begin(9600); // Setup serial
// Initialize the button pin as a input with pullup, active low
pinMode(buttonPin, INPUT_PULLUP);
//Initialize button states
buttonState = digitalRead(buttonPin);
lastButtonState = buttonState;
lcd.backlight();
lcd.begin(16, 3);
lcd.setCursor(0, 0);
lcd.print(" !!!WELCOME!!! ");
lcd.setCursor(0, 1);
lcd.print("Valves Resetting ");
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Valves Closed ");
lcd.setCursor(0, 1);
lcd.print("Quiet Mode");
lcd.noBacklight();
Serial.println("Exhaust Valves ");
}
void loop()
{
// Read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// Compare the buttonState to its previous state
if (buttonState != lastButtonState) //Changed
{
if (buttonState == LOW) //New press, so change valve flag
{
valveStatus = !valveStatus;
}
delay(50);
}
lastButtonState = buttonState; // Save the current state as the last state, for next time through the loop
if (valveStatus) //Positions the valve
{
Serial.write(0x56);
Serial.write(0x31);
Serial.write(0x0A);
Serial.print("Valve Status: ");
Serial.print(" Valve Open");
Serial.println(" (Loud Mode)");
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Valves Open ");
lcd.setCursor(0, 1);
lcd.print("Loud Mode ");
lcd.noBacklight();
}
else
{
Serial.write(0x56);
Serial.write(0x30);
Serial.write(0x0A);
Serial.print("Valve Status: ");
Serial.print(" Valve Closed");
Serial.println(" (Quiet Mode)");
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Valves Closed ");
lcd.setCursor(0, 1);
lcd.print("Quiet Mode ");
lcd.noBacklight();
}
}
Mike.
Last edited by a moderator: