i am trying to accomplish a menu on a 20x4 lcd, the screens do change but i want the first page to have blinking text and be the default page... the button will allow me to go through the pages.. but say i click the button once.. but not again i want it to go back to the blinking text page after so much time like a delay, each page will have this delay if you know what i mean..
#include <Wire.h>
#include <hd44780.h> // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
hd44780_I2Cexp lcd; // declare lcd object: auto locate & config exapander chip
// LCD geometry
const int LCD_COLS = 20;
const int LCD_ROWS = 4;
int WhichScreen = 1; // This variable stores the current Screen number
boolean hasChanged = true;
const int buttonPin = 3; // the number of the pushbutton pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup()
{
int status;
status = lcd.begin(LCD_COLS, LCD_ROWS);
pinMode(buttonPin, INPUT);
}
void loop()
{
if (hasChanged == true) {
switch (WhichScreen) {
case 1:
{
firstScreen();
}
break;
case 2:
{
secondScreen();
}
break;
case 3:
{
thirdScreen();
}
break;
case 0:
{
}
break;
}
}
//-------------------------------
// BEGIN of the switch debouncing code
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
hasChanged = true;
WhichScreen++;
}
} else {
hasChanged = false;
}
}
lastButtonState = reading;
// END of the switch Debouncing code
// --------------------------------------
if (WhichScreen > 3) {
WhichScreen = 1;
}
}
void firstScreen()
{
// loop repeatedly until the button is pressed
// return to this screen after a delay after button
// is pressed but not pressed again within a certain amount of time
lcd.clear();
lcd.setCursor(0, 0); // Column, line
lcd.print(" MY INTRO ");
lcd.setCursor(0, 1);
lcd.print(" BLINKING ");
lcd.setCursor(0, 2);
lcd.print(" SPLASH ");
lcd.setCursor(0, 3);
lcd.print(" SCREEN ");
}
void secondScreen()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("PHRASE 1:");
lcd.setCursor(0, 1);
lcd.print("PHRASE 2:");
lcd.setCursor(0, 2);
lcd.print("PHRASE 3:");
lcd.setCursor(0, 3);
lcd.print("PHRASE 4:");
}
void thirdScreen()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("PHRASE 1:");
lcd.setCursor(0, 1);
lcd.print("PHRASE 2:");
lcd.setCursor(0, 2);
lcd.print("PHRASE 3:");
lcd.setCursor(0, 3);
lcd.print("PHRASE 4:");
}