My program works fine, uses 3 alarms to turn different lights on and off daily. Just wondering if it could be made better. I am using a Leonardo board which I know is different from an uno board.
/*
*/
#include <Time.h>
#include <TimeAlarms.h>
//#include "Wire.h"
#include <LiquidCrystal.h>
const int MorningAlarmPin1 = A1; // Blue Lights ON
const int EveningAlarmPin1 = A1; // Blue Lights OFF
const int MorningAlarmPin2 = A2;
const int EveningAlarmPin2 = A2;
const int MorningAlarmPin3 = A3;
const int EveningAlarmPin3 = A3;
const int ledPin = A1;
const int ledPin2 = A2;
const int ledPin3 = A3;
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7);
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : H E A T E R O F F |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void setup()
{
lcd.begin(16, 2);
lcd.setCursor(0, 0);
setTime(12,59,30,2,23,14); // set time to Saturday 8:29:00am Jan 1 2011
// create the alarms
Alarm.alarmRepeat(8,30,0, MorningAlarm); // Time Blue's come on every day
Alarm.alarmRepeat(10,32,0,EveningAlarm); // Time Blue's shut off every day
Alarm.alarmRepeat(8,30,0,MorningAlarm2);
Alarm.alarmRepeat(10,31,0,EveningAlarm2);
Alarm.alarmRepeat(8,30,0,MorningAlarm3);
Alarm.alarmRepeat(10,33,0,EveningAlarm3);
pinMode(MorningAlarmPin1, OUTPUT); // set the digital pin as output:
pinMode(EveningAlarmPin1, OUTPUT); // set the digital pin as output:
pinMode(MorningAlarmPin2, OUTPUT);
pinMode(EveningAlarmPin2, OUTPUT);
pinMode(MorningAlarmPin3, OUTPUT);
pinMode(EveningAlarmPin3, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
void loop(){
digitalClockDisplay();
Alarm.delay(1000); // wait one second between clock display
}
// functions to be called when an alarm triggers:
void MorningAlarm(){
lcd.setCursor(0,0);
lcd.print("BLUE ON ");
digitalWrite(ledPin,LOW);
}
void EveningAlarm(){
lcd.setCursor(0,0);
lcd.print("BLUE OFF");
digitalWrite(ledPin,HIGH);
}
void MorningAlarm2(){
lcd.setCursor(0,1);
lcd.print("WHITE ON ");
digitalWrite(ledPin2,LOW);
}
void EveningAlarm2(){
lcd.setCursor(0,1);
lcd.print("WHITE OFF");
digitalWrite(ledPin2,HIGH);
}
void MorningAlarm3(){
lcd.setCursor(10,1);
lcd.print("M ON ");
digitalWrite(ledPin3,LOW);
}
void EveningAlarm3(){
lcd.setCursor(10,1);
lcd.print("M OFF ");
digitalWrite(ledPin3,HIGH);
}
void digitalClockDisplay()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}
void printDigits(int digits)
{
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}