Alarm.alarmRepeat LCD print problem

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"); 
}

click the MODIFY button in the upper right of the post window.
Highlight all you code.
click the "#" CODE TAGS button on the toolbar above just to the left of the QUOTE button.
click SAVE (at the bottom).
When you post code on the forum, please make a habit of using the code tags "#" button.

  1. There is never a use for a relay look up transistor - they are cheaper, faster, don't keep going click and easier to use.

  2. Format (tools menu) on the IDE before posting (for our sake) and for your own - lots of logic errors show up when code is correct formatted.

Mark

Sorry for my mistakes. I made some corrections and the code should be better to read now.

  lcd.print('AlarmOn');

try   lcd.print("AlarmOn"); 

Post ALL the code the things before setup do matter!

Mark

If i use this code:

 lcd.print("AlarmOn");

Then it prints to LCD text "AlarmOn", but i want it to prints AlarmOn value which i mean is "21,59,10".

Post your entire sketch if you want help. We are not going to work from "snippets"

There is all code i have.

Move ALL your pinMode statements from the functions and put them in Setup

Each alarm that you set has an ID which is set when the alarm is created

  int repeatID = Alarm.alarmRepeat(21,59,10, AlarmOn);  // Relay turns ON

You can use the ID to get the alarm time using the Alarm.read() method and you can convert the value returned into hours, minutes and seconds using the hour(), minute() and second() functions.

  Serial.print(hour(Alarm.read(repeatID)));
  Serial.print(":");
  Serial.print(minute(Alarm.read(repeatID)));
  Serial.print(":");
  Serial.println(second(Alarm.read(repeatID)));

Note that you will need to check the value returned by hour(), minute() and second() and pad with leading zeroes to make the display consistent.

I tried this code different ways. Best solution, what i got was that alarming time was printed to LCD once. After that the LCD showed RTC time. I can't figure out, why its changing alarm value to RTC value. I will add my code, what i have now.

#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()); 
}
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);
  }
  // Alarms 
  int repeatID = Alarm.alarmRepeat(21,59,10, AlarmOn);  // Relay turns ON 
  int repeatID2 = Alarm.alarmRepeat(21,59,30, AlarmOff);  // Relay turns OFF
  lcd.setCursor(0, 1);
  lcd.print("Alarm ON");
  lcd.print(hour(Alarm.read(repeatID)));
  lcd.print(":");
  lcd.print(minute(Alarm.read(repeatID)));
  lcd.print(":");
  lcd.println(second(Alarm.read(repeatID)));

}
// Alarm Functions ON
void AlarmOn(){
  pinMode(led, OUTPUT);  
  digitalWrite(led, HIGH);    
  delay(1000);               
  digitalWrite(led, LOW);     
  delay(1000);   
}

// Alarm Functions OFF
void AlarmOff(){
  pinMode(led, OUTPUT);  
  digitalWrite(led, HIGH);     
  delay(1000);               
  digitalWrite(led, HIGH);     
  delay(1000);               
  Serial.println("Alarm OFF"); 
}

There are a number of things about your code that have me confused.

  setTime(hour(), minute(), second(), day(), month(), year());
  setTime(now.hour(),now.minute(),now.second(),now.day(),now.month(),now.year());

Do you really need both of these lines ?

  { 
    if(now.hour() < 10)
      lcd.print('0');
    lcd.print(now.hour(), DEC);
  }

What is the purpose of the braces ? There are several instances of this in the program.

  int repeatID = Alarm.alarmRepeat(21,59,10, AlarmOn);  // Relay turns ON 
  int repeatID2 = Alarm.alarmRepeat(21,59,30, AlarmOff);  // Relay turns OFF

Why are these lines in the loop() function ? Surely you only need to set the alarm times once in setup, or in loop() if they change. One side effect of this is that there is a limit as to how many alarms you can have active and doing it this way you will very soon run out. This is quite probably causing your problem with the alarm time not being displayed. Move the alarm definitions to setup() and see what happens.

  lcd.begin(16, 2);You only need to do this once, not every time through loop(). If you want to clear the LCD then use lcd.clear();

 { 
    if(now.hour() < 10)
      lcd.print('0');
    lcd.print(now.hour(), DEC);
  }

That means, if numbers (seconds, hours, minutes) are lower than "10" then it prints to LCD number "0" so the number is for example "05" instead of "5".

int repeatID = Alarm.alarmRepeat(21,59,10, AlarmOn);  // Relay turns ON 
int repeatID2 = Alarm.alarmRepeat(21,59,30, AlarmOff);  // Relay turns OFF

If i use those codes in setup() and trying to print AlarmOn value to LCD in Loop(), then it says: error: 'repeatID' was not declared in this scope

Other cases your comments were right, what you said earlier.

Move ALL your pinMode statements from the functions and put them in Setup

Please take a look at

http://arduino.cc/en/Reference/scope

an understanding of the scope of variables will help with your programming.

Mix352:

 { 

if(now.hour() < 10)
      lcd.print('0');
    lcd.print(now.hour(), DEC);
  }



That means, if numbers (seconds, hours, minutes) are lower than "10" then it prints to LCD number "0" so the number is for example "05" instead of "5".

I know what the code does. I was asking what the braces were for.

int repeatID = Alarm.alarmRepeat(21,59,10, AlarmOn);  // Relay turns ON 

int repeatID2 = Alarm.alarmRepeat(21,59,30, AlarmOff);  // Relay turns OFF




If i use those codes in setup() and trying to print AlarmOn value to LCD in Loop(), then it says: error: 'repeatID' was not declared in this scope

That is because the IDs are declared as local variables. Declare them as global variables and create the alarms in setup(). You will then be able to use the variables in the loop() function.