Hi this is my first time posting in the forum so I apologize in advance for my newness. I code a little and I really want some experience using arduino so I'm using an uno to make an RTC alarm clock. I have an LCD screen and 3 buttons in pullup configuration and an SPST switch attached. The buttons are Set/snooze, increment hours and increment minutes. The switch lets the user pick between setting the time or setting an alarm. The default screen always shows the time and date.
From the default screen, the user holds the set button for 2 seconds to enter either the time or alarm set mode depending on the position of the switch. I want to increment hours and minutes the same way for both settings and simply save them into their own variables and eventually compare them to sound an alarm. My problem is the hours and minutes do not increment when I push either the hours or minutes button. I understand I have not coded a way for the user to get back to the default screen. I was thinking a 10 second timeout after no button pushes is best but I can't get anything to increment. I can display the time and date and holding the set button for 2 seconds enters the correct modes but the hours and minutes buttons do nothing.
I'm using the DS1307 breakout board from adafruit and I'm also using RTClib. I'm planning to switch these buttons to the analog pins after I add the wave shield from adafruit as well to sound the alarm. I've only been testing for the alarm setting mode since I want the time setting mode to essentially do the same thing. I didn't show the other functions because they work properly. It's just this function I'm having trouble with. Any help would be greatly appreciated
void loop ()
{
now = rtc.now();
lcd.clear();
displayTime();
modeState = digitalRead(modeSetPin);
incHoursState = digitalRead(incHoursPin);
incMinsState = digitalRead(incMinsPin);
setMode();
}
void setMode()
{
if (modeState == LOW)
{
Serial.println("Test 1");
Serial.println(modeButtonCount);
if (modeButtonCount > 1)// Mode button held for 2s
{
if (digitalRead(setTimeAlarmSw) == HIGH)
{
//Setting Alarm
Serial.println("Test 2");
lcd.clear();
lcd.home();
lcd.print("Snooze to Set");
lcd.setCursor(0, 1);
lcd.print("Alarm = ");
if (incHoursState == LOW)
{
Serial.print("aHr: ");
Serial.println(aHr);
aHr++;
if (aHr > 23)
{
aHr = 0;
aMins = 0;
aSecs = 0;
}
}
if (incMinsState == LOW)
{
Serial.print("aMins: ");
Serial.println(aMins);
aMins++;
if (aMins > 59)
{
aMins = 0;
}
}
displayAlarm();
delay(3000);
modeButtonCount = 0;
}
//Setting Time
else
{
lcd.clear();
lcd.home();
lcd.print("Snooze to Set");
lcd.setCursor(0, 1);
lcd.print("Time = ");
//setDateTime();
delay(3000);
modeButtonCount = 0;
}
}
else
{
modeButtonCount++;
Serial.println(modeButtonCount);
}
}
}