I have an Arduino project to do, which requires a countdown timer(which I've already done). I connected a push button, and when I press that button I need it to increase my countdown timer by +10 seconds.
Can anyone help me with adding the code for this button?
Here is the code so far(I declared the button, but I don't know if it's any good):
#include <LiquidCrystal.h>
int buttonPin = 7;
int buttonState = 0;
int seconds = 30; // count seconds
int minutes = 0; // count minutes
int hours = 0; // count hours
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // pins connected to LCD
void setup()
{
lcd.begin(16, 2); //set up the LCD's number of columns and rows
pinMode(buttonPin, INPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin);
lcd.setCursor(1, 0);
lcd.print ("Sosire in:");
lcd.setCursor(6, 1);
lcd.print(":");
lcd.setCursor(9, 1);
lcd.print(":");
seconds--;
delay(1000);
if (seconds < 0)
{
minutes--;
seconds = 59;
}
if (minutes < 0)
{
hours--;
minutes = 59;
}
if (hours < 0)
{
hours = 0;
minutes = 0;
seconds = 30;
}
if (minutes > 9)
{
lcd.setCursor(7, 1);
lcd.print(minutes);
}
else
{
lcd.setCursor(7, 1);
lcd.print("0");
lcd.setCursor(8, 1);
lcd.print(minutes);
lcd.setCursor(9, 1);
lcd.print(":");
}
if (seconds > 9)
{
lcd.setCursor(10, 1);
lcd.print(seconds);
}
else
{
lcd.setCursor(10, 1);
lcd.print("0");
lcd.setCursor(11, 1);
lcd.print(seconds);
lcd.setCursor(12, 1);
lcd.print(" ");
}
if (hours > 9)
{
lcd.setCursor(4, 1);
lcd.print(hours);
}
else
{
lcd.setCursor(4, 1);
lcd.print("0");
lcd.setCursor(5, 1);
lcd.print(hours);
lcd.setCursor(6, 1);
lcd.print(":");
}
if (seconds == 0)
{
lcd.clear();
lcd.print("Este in statie");
delay(5000);
lcd.clear();
}
}