So I'm working on this project and when I'm launching the code for this timer, the LCD display connected displays an extra zero at the end of the timer (00:00:000 when initialized on the arduino). I've looked through the code, but I don't know why there's a third zero attached to the end. Any help would be greatly appreciated. Thanks.
Code: Select all
#include <TimerOne.h>
#include <LiquidCrystal.h>
int secs = 0;
int secsForMin = 0;
int secsForHours = 0;
const int buttonPin = 2;
LiquidCrystal lcd(12, 11, 6, 5, 4, 3);
void setup()
{
Timer1.initialize(1000000); // set a timer of length 1000000 microseconds (or 1 sec - or 1Hz)
Timer1.attachInterrupt( timerIsr ); // attach the service routine here
attachInterrupt(0, resetTimer, FALLING);
}
void loop()
{
timerLCD();
}
void timerLCD() {
if(secsForHours < 216000) {
if(secsForHours < 36000) {
lcd.print("0");
lcd.setCursor(1, 1);
lcd.print(secsForHours / 3600);
}
else {
lcd.print(secsForHours / 3600);
}
}
else{
lcd.print("00");
secsForHours = 0;
}
lcd.setCursor(2, 1);
lcd.print(":");
lcd.setCursor(3, 1);
if(secsForMin < 3600) {
if(secsForMin < 600) {
lcd.print("0");
lcd.setCursor(4, 1);
lcd.print(secsForMin / 60);
}
else {
lcd.print(secsForMin / 60);
}
}
else {
lcd.print("00");
secsForMin = 0;
}
lcd.setCursor(5, 1);
lcd.print(":");
lcd.setCursor(6, 1);
if(secs < 60) {
if(secs < 10) {
lcd.print("0");
lcd.setCursor(7, 1);
lcd.print(secs);
}
else {
lcd.print(secs * 1);
}
}
else {
lcd.print("00");
secs = 0;
}
}
/// --------------------------
/// Custom ISR Timer Routine
/// --------------------------
void timerIsr() {
secs ++;
secsForMin ++;
secsForHours ++;
}
void resetTimer () {
secs = 0;
secsForMin = 0;
secsForHours = 0;
}