Hey everyone,
I'm working on and what I'm trying to do is to switch the text on the LCD display everytime the button is pressed. I think I'm pretty close but I'm sure I'm messing up when it comes to the state of the button. I'm outside right now so I wont be able to make edits for a few hours but here's my code:
// include the library code:
#include<LiquidCrystal.h>
int buttonState = 0; //initialize push button state
int pb = 6; //initialize push button state
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int counter = 0;
void setup() {
pinMode(pb, INPUT); //set pb as input
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// lcd.setCursor(0, 1);
// lcd.clear();
lcd.print("Dad Joke 4000");
}
void loop() {
while (counter == 0) {
buttonState = digitalRead(pb);
if (buttonState == HIGH) {
lcd.clear();
lcd.print("test");
lcd.setCursor(0,1);
lcd.print("jason");
lcd.setCursor(0,0);
delay(3000);
counter = 1;
} else if (counter == 1 && buttonState == HIGH) {
lcd.clear();
lcd.print("Test Failed");
}
}
}
The problem is that the text stays on the screen after the button press. I want to change the text on each press / move into the next else if statement