I am using a button switch to change text on my LCD screen but it keep jumping back a for between the text and i cant figure out why.
Arduino Nano
16,2 LCD screen
push button
#include <LiquidCrystal.h>
int rs=7;
int en=8;
int d4=9;
int d5=10;
int d6=11;
int d7=12;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
int buttonPin = 5;
int button = HIGH;
int buttonNew;
int buttonOld = LOW;
unsigned long time = 0;
unsigned long debounce = 200UL;
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
pinMode(buttonPin, INPUT);
}
void loop(){
Serial.println(button);
buttonNew = digitalRead(buttonPin);
if (buttonNew == HIGH && buttonOld == LOW && millis() - time > debounce)
{
if (button == HIGH){
button = LOW;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("HELLO WORLD");
}
else
button = HIGH;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("GOODBUY");
time = millis();
}
buttonOld = buttonNew;
}