// NBlizard 8/28/2022
// start egg timer from scratch
// then incorporate 4dig 7segment LED array and calls to show countdown time
byte BUTTON_1 = A0;
byte BUTTON_2 = A1;
byte BUTTON_3 = A2;
bool PRESSED = LOW;
bool BUTTON_1_STATE = !PRESSED;
bool BUTTON_2_STATE = !PRESSED;
bool BUTTON_3_STATE = !PRESSED;
void setup() {
pinMode(BUTTON_1, INPUT_PULLUP);
pinMode(BUTTON_2, INPUT_PULLUP);
pinMode(BUTTON_3, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly
// initialize time to display
int timeToDisplay = 0;
// read state of button 1
BUTTON_1_STATE = digitalRead(BUTTON_1);
// debounce button
BUTTON_2_STATE = digitalRead(BUTTON_2);
// debounce button
BUTTON_3_STATE = digitalRead(BUTTON_3);
// debounce button
if (BUTTON_1_STATE == PRESSED) {
timeToDisplay = Button_1_SetTimer();
// debounce button
// reset state
BUTTON_1_STATE = !PRESSED;
// call countdowntimer
//Serial.println(timeToDisplay);
Count_Down_Timer(timeToDisplay);
}
if (BUTTON_2_STATE == PRESSED) {
timeToDisplay = Button_2_SetTimer();
// debounce button
// reset state
BUTTON_2_STATE = !PRESSED;
// call countdowntimer
//Serial.println(timeToDisplay);
Count_Down_Timer(timeToDisplay);
}
}
// function for Button_1
int Button_1_SetTimer () {
// set display to 12
int timeToDisplay = 12;
return timeToDisplay;
}
// function for Button_2
int Button_2_SetTimer () {
// set display to
int timeToDisplay = 105; // remember this is minutes:seconds, parse out seconds
return timeToDisplay;
}
void Count_Down_Timer (int displayTime) {
int countDown = displayTime;
for ( int countDown = displayTime; countDown >= 0; countDown--) {
// set the time delay
unsigned long futureTime = millis() + 1000; // adding 1 second to future time
// now do nothing for 1 second
while ( millis() < futureTime) {
// refresh display
//check button3 for reset
if (Check_Button_3()) { // if reset, set counDown to 0 and break
Serial.println("Reset");
countDown = 0;
break;
}
}
// special case if 100 (1 minute)
if (countDown == 99) {
countDown = 59;
}
Serial.println(countDown);
}
}
// this function continously checks for reset, it must be called in countdowntimer
bool Check_Button_3 () {
// continue to read button 3 for reset
bool Reset_Flag = false;
BUTTON_3_STATE = digitalRead(BUTTON_3);
if (BUTTON_3_STATE == PRESSED) {
Reset_Flag = true;
}
return Reset_Flag;
}