#include<LiquidCrystal.h>
LiquidCrystal lcd(9, 8, 2, 3, 4, 5);//RS,E,DB4,DB5,DB6,DB7
const int switchPin1 = 10;
//const int switchPin2 = 11;
int led = 13;
//const int switchPin3 = 12;
long minutes=0, second =10;
long countdown = (minutes*60)+ second;
long start;
int prevbuttonState1 = 0;
bool enabled = false;
void setup()
{
lcd.begin(16, 2);
lcd.print("hello, world!");
delay(2000);
lcd.clear();
lcd.print("Select Mode");
pinMode( switchPin1, INPUT_PULLUP);
pinMode(led, OUTPUT);
//long start = millis();
}
void loop()
{
int buttonState1 = digitalRead(switchPin1);
//pressed button 1
if (buttonState1 == HIGH && prevbuttonState1== LOW) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MODE 1"); //lcd display mode 1
prevbuttonState1 = buttonState1;}
//after button 1 is pushed
if (digitalRead(switchPin1) == 1) {
//timer coding start
digitalWrite(led, HIGH);
long start = millis();
long countdowntime_seconds = countdown - (millis() - start)/1000;
//while door is closed
while (countdowntime_seconds > 0) {
long countdowntime_seconds = countdown - (millis() - start)/1000;
//if (countdowntime_seconds >= 0) {
//conversion to min and sec
long countdown_minute = ((countdowntime_seconds / 60) % 60);
long countdown_sec = countdowntime_seconds % 60;
lcd.setCursor(5, 1);
if (countdown_minute < 10)
lcd.print("0");
lcd.print(countdown_minute);
lcd.print(":");
if (countdown_sec < 10)
lcd.print("0");
lcd.print(countdown_sec);
}
//times up
//if (countdowntime_seconds == 0)
{
digitalWrite(led, LOW);
}
//else {
//digitalWrite(led, HIGH);
// }
}
}
may i know why after the countdown finished it still like this? for now i only test using 1 button only.
