I have made a simple timer to show the seconds since the last time the clear button was pressed (button1). it has a pause button (button2) and in the code it is supposed to pause the timer when it is pressed, the clear button works fine but the board is "ignoring" the pause button no matter what i do. any ideas? everything i have found is either too irrelevant to use or doesn't make sense.
'
//This program simply states the number of seconds
//since the last reset, along with a "Hello World!" text.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int seconds = 0;
const int button1 = 8;
const int button2 = 7;
int result = 0;
int oldButtonState = LOW;
int newButtonState;
void setup() {
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT);
lcd.begin(16, 2);
// 0,0 is first line, first row; 0,1 is second line, first row
lcd.print("STARTING UP");
delay(600);
for (int x=0; x <= 2; x++){
lcd.clear();
lcd.print("Please Wait");
delay(600);
lcd.clear();
lcd.print("Please Wait.");
delay(600);
lcd.clear();
lcd.print("Please Wait..");
delay(600);
lcd.clear();
lcd.print("Please Wait...");
delay(600);
}
lcd.clear();
delay(670);
}
void loop() {
if (digitalRead(button2) == HIGH){newButtonState = HIGH;}
else if(digitalRead(button2) == LOW){newButtonState = LOW;}
oldButtonState = LOW;
if (newButtonState == HIGH && oldButtonState == LOW){
//button was pressed, but not now
while(newButtonState == HIGH && oldButtonState == LOW){
seconds++;
if (digitalRead(button1) == LOW){
seconds = 0;
}
lcd.clear();
lcd.print("Counter v1.5");
lcd.setCursor(0,1);
lcd.print("Seconds: ");
lcd.print(seconds);
delay(1000);
}
}
else if (newButtonState == LOW && oldButtonState == HIGH){
//button wasnt pressed, but is now
while(newButtonState == LOW && oldButtonState == HIGH){
lcd.clear();
lcd.print("PAUSED");
delay(500);
}
}
oldButtonState = newButtonState;
}