I've been trying to make a timer with Arduino that will stop after 2 hours and make a buzzer go off. I've been succesful with getting the timer count seconds up, but now I've tried to make it display hours and minutes too & make buzzer go off, all help is appreciated, here is the code and picture of project:
#include <LiquidCrystal.h>
LiquidCrystal lcd(1,2,4,5,6,7); // setup the lcd
#define button 3
// setup integers //
int timerMode=0;
int buzzer=8;
int wait=400;
int longWait=5000;
int startTime;
int hours=(millis() - startTime) / 360000;
void setup() {
lcd.begin(16,2); // start lcd //
lcd.clear(); // clear old text //
pinMode(button, INPUT_PULLUP); // make button an input //
pinMode(buzzer, OUTPUT); // make buzzer an output //
lcd.print("Ergo timer"); // print begin text //
}
void loop() {
lcd.setCursor(0,1);
if (digitalRead(button) == LOW){ // if button is pressed//
startTime=millis();
timerMode++;
delay(wait);
}
if (timerMode==1){ // if timermode is 1 after a button press //
lcd.setCursor(0,0);
lcd.print("Over 2 uur pause"); // print top text //
lcd.setCursor(0,5);
lcd.print( (millis() - startTime) / 1000); // print time in seconds //
lcd.setCursor(0,4);
lcd.print(":"); // print a column between //
lcd.setCursor(0,3);
lcd.print( (millis() - startTime) / 60000); // print time in minutes //
lcd.setCursor(0,2);
lcd.print(":");
lcd. setCursor(0,1);
lcd.print( (millis() - startTime) / 360000); // print time in hours //
}
if (hours == 2){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("---Nu pause---");
tone(buzzer,200,1000);
}
if (timerMode > 1){
delay(longWait);
timerMode=0;
lcd.clear();
lcd.print("---Ergo timer---");
}