So i've made a countdown timer and it works fairly well for what i am doing, however i wanted to add a feature. as it is i have 4 buttons: 10 second countdown, 20 second countdown, 40 second countdown, and a reset. the feature i would like to add is if when reset is pressed during a countdown if it could store the time remaining so i could resume a few moments later with the press of the same reset button. i am also up for any other critiques as i have only been messing with my arduino for a few weeks. also keep in mind i have moved this project off of the uno and onto a attiny85 to save space and money as i plan to make a few of these, so interrupts are probably not an option. heres what i have so far...
//setup buttons and buzzer pins
const int buzz = 4;
const int butt1 = 0;
const int butt2 = 1;
const int butt3 = 2;
const int butt4 = 3;
void setup() {
//setup pinModes as input and outputs
pinMode(buzz, OUTPUT);
pinMode(butt1, INPUT);
pinMode(butt2, INPUT);
pinMode(butt3, INPUT);
pinMode(butt4, INPUT);
//setup serial comunication for monitoring time
Serial.begin(9600);
}
void loop()
{
//button 1 sequence
if (digitalRead(butt1) == LOW)
{
//beep twice for an audible confirmation of button press
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
delay(50);
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
//10 second countdown
for (int x = 10; x >= 0; x--)
{
if (x == 0)
{
digitalWrite(buzz, HIGH);
delay(2000);
digitalWrite(buzz, LOW);
}
//alow for a reset and beep three times if pressed
if (digitalRead(butt4) == LOW)
{
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
delay(50);
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
delay(50);
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
break;
}
else
{
Serial.println(x);
delay(1000);
}
}
}
//button 2 sequence
if (digitalRead(butt2) == LOW)
{
//beep twice for an audible confirmation of button press
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
delay(50);
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
//20 second countdown
for (int x = 20; x >= 0; x--)
{
if (x == 0)
{
digitalWrite(buzz, HIGH);
delay(2000);
digitalWrite(buzz, LOW);
}
//alow for a reset and beep three times if pressed
if (digitalRead(butt4) == LOW)
{
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
delay(50);
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
delay(50);
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
break;
}
else
{
Serial.println(x);
delay(1000);
}
}
}
//button 3 sequence
if (digitalRead(butt3) == LOW)
{
//beep twice for an audible confirmation of button press
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
delay(50);
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
//40 second countdown
for (int x = 40; x >= 0; x = x--)
{
if (x == 0)
{
digitalWrite(buzz, HIGH);
delay(2000);
digitalWrite(buzz, LOW);
}
//alow for a reset and beep three times if pressed
if (digitalRead(butt4) == LOW)
{
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
delay(50);
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
delay(50);
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
break;
}
else
{
Serial.println(x);
delay(1000);
}
}
}
}