I have a problem with LCD printing. Project's main idea is to turn relay ON and OFF between alarm period. My problem is that how can I print to LCD AlarmOn value (21,59,10)? I know, that i can write manually alarm times to LCD. Is there solution, that prints my alarm values automatically to LCD when i change alarming times? I tried lcd.print('AlarmOn'); but it isnt working.
Here is my piece of code:
#include <Wire.h>
#include "RTClib.h"
#include <Time.h>
#include <TimeAlarms.h>
#include <LiquidCrystal.h>
int led = 7; //5v signal to relay
//int led2 = 8; //5v signal to reed relay
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
RTC_DS1307 RTC;
void setup()
{
Serial.begin(57600);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
DateTime now = RTC.now();
setTime(hour(), minute(), second(), day(), month(), year());
setTime(now.hour(),now.minute(),now.second(),now.day(),now.month(),now.year());
// Alarms
Alarm.alarmRepeat(21,59,10, AlarmOn); // Relay turns ON
Alarm.alarmRepeat(21,59,30, AlarmOff); // Relay turns OFF
}
void loop(){
DateTime now = RTC.now();
setTime(now.hour(),now.minute(),now.second(),now.day(),now.month(),now.year()); // set time & date
Alarm.delay(1000); //clock display delay
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
lcd.begin(16, 2);
lcd.print("Aeg:");
{
if(now.hour() < 10)
lcd.print('0');
lcd.print(now.hour(), DEC);
}
lcd.print(':');
{
if(now.minute() < 10)
lcd.print('0');
lcd.print(now.minute(), DEC);
}
lcd.print(':');
{
if(now.second() < 10)
lcd.print('0');
lcd.print(now.second(), DEC);
}
lcd.setCursor(1, 2);
lcd.print("On:");
lcd.print('AlarmOn');
}
// Alarm Functions
void AlarmOn(){
pinMode(led, OUTPUT);
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
Serial.println("Alarm ON");
lcd.begin(1, 1);
lcd.print("On:");
lcd.print('AlarmOn');
}
void AlarmOff(){
pinMode(led, OUTPUT);
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, HIGH);
delay(1000);
Serial.println("Alarm OFF");
}