I have a sketch I need assistance with. The problem is that the LEDs don't seem to turn on when they are supposed to.
I've looked at the Time.h and TimeAlarms.h documentation trying to figure it out, and I think maybe there is something I've severly overlooked.
I'm using an Arduino UNO with a ds1307 as a RTC. I set the RTC with another script. The time appears to be reporting correctly when I check the serial monitor.
Any ideas on what may be wrong? (Don't laugh too hard, I know my baby is ugly right now) But It's my first rev! It's the only way I know how I think I can do it, and well, I'm not doing it right. Suggestions will be most appreciated! Here is the code:
/*
* Time_Rev2.ino
*
* This is a sketch for a 3 LED clock that is supposed to light LEDs at certain times.
*
* Monday-Friday: Blue 6:35p - 5:29a
* Yellow 5:30a - 5:59a
* Green 6:00a - 7:00a
* OFF 7:01a - 6:34p
*
* Saturday/Sunday: Blue 6:35p - 6:29a
* Yellow 6:30a - 6:59a
* Green 7:00a - 8:00a
* OFF 8:00a - 6:34p
*
*/
#include <Wire.h>
#include "RTClib.h"
#include <Time.h>
#include <TimeAlarms.h>
int bluePin = 13; // Blue LED connected to digital pin 13
int yellowPin = 12; // Yellow LED connected to digital pin 12
int greenPin = 11; // Green LED connected to digital pin 11
int delayTime = 1000; // initiate a delaytime amount here
RTC_DS1307 RTC;
void setup () {
Serial.begin(57600);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
}
DateTime now = RTC.now();
setTime(hour(), minute(), second(), day(), month(), year());
setTime(now.hour(),now.minute(),now.second(),now.day(),now.month(),now.year()); // set time & date
// Monday Through Friday Alarms
Alarm.alarmRepeat(dowMonday, 18,35,0, Blue);
Alarm.alarmRepeat(dowMonday, 5,30,0, Yellow);
Alarm.alarmRepeat(dowMonday, 6,00,0, Green);
Alarm.alarmRepeat(dowTuesday, 18,35,0, Blue);
Alarm.alarmRepeat(dowTuesday, 5,30,0, Yellow);
Alarm.alarmRepeat(dowTuesday, 6,00,0, Green);
Alarm.alarmRepeat(dowWednesday, 18,35,0, Blue);
Alarm.alarmRepeat(dowWednesday, 5,30,0, Yellow);
Alarm.alarmRepeat(dowWednesday, 6,00,0, Green);
Alarm.alarmRepeat(dowThursday, 18,35,0, Blue);
Alarm.alarmRepeat(dowThursday, 5,30,0, Yellow);
Alarm.alarmRepeat(dowThursday, 6,00,0, Green);
Alarm.alarmRepeat(dowFriday, 18,35,0, Blue);
Alarm.alarmRepeat(dowFriday, 5,30,0, Yellow);
Alarm.alarmRepeat(dowFriday, 6,00,0, Green);
// Saturday and Sunday Alarms
Alarm.alarmRepeat(dowSaturday, 18,35,0, Blue);
Alarm.alarmRepeat(dowSaturday, 6,30,0, Yellow);
Alarm.alarmRepeat(dowSaturday, 8,00,0, Green);
Alarm.alarmRepeat(dowSunday, 18,35,0, Blue);
Alarm.alarmRepeat(dowSunday, 6,30,0, Yellow);
Alarm.alarmRepeat(dowSunday, 8,00,0, Green);
// Times that ALL LED's should be off
Alarm.alarmRepeat(dowSunday, 8,00,0, Off);
Alarm.alarmRepeat(dowMonday, 7,01,0, Off);
Alarm.alarmRepeat(dowTuesday, 7,01,0, Off);
Alarm.alarmRepeat(dowWednesday, 7,01,0, Off);
Alarm.alarmRepeat(dowThursday, 7,01,0, Off);
Alarm.alarmRepeat(dowFriday, 7,01,0, Off);
Alarm.alarmRepeat(dowSaturday, 8,00,0, Off);
pinMode(bluePin, OUTPUT); // sets the digital pin as output
pinMode(yellowPin, OUTPUT); // sets the digital pin as output
pinMode(greenPin, OUTPUT); // sets the digiral pin as output
}
void loop(){
digitalClockDisplay();
Alarm.delay(1000); // wait one second between clock display
}
void digitalClockDisplay(){
// digital clock display of time & date
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(month());
Serial.print("/");
Serial.print(day());
Serial.print("/");
Serial.print(year());
Serial.println();
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
// *******************
// call alarm triggers
// *******************
void Blue()
{
Serial.println("Blue");
digitalWrite(bluePin, HIGH); // sets the Blue LED on
digitalWrite(yellowPin, LOW); // sets the Yellow LED off
digitalWrite(greenPin, LOW); // sets the Green LED off
}
void Yellow()
{
Serial.println("Yellow");
digitalWrite(bluePin, LOW); // sets the Blue LED off
digitalWrite(yellowPin, HIGH); // sets the Yellow LED on
digitalWrite(greenPin, LOW); // sets the Green LED off
}
void Green()
{
Serial.println("Green");
digitalWrite(bluePin, LOW); // sets the Blue LED off
digitalWrite(yellowPin, LOW); // sets the Yellow LED off
digitalWrite(greenPin, HIGH); // sets the Green LED on
}
void Off()
{
Serial.println("Off");
digitalWrite(bluePin, LOW); // sets the Blue LED off
digitalWrite(yellowPin, LOW); // sets the Yellow LED off
digitalWrite(greenPin, LOW); // sets the Green LED off
}