Go Down

Topic: Time and TimeAlarms Libraries – Ask here for help or suggestions (Read 219484 times) previous topic - next topic

EnigmaCypher7

Bob808,

Though this will not help your post, I understand your frustration. New users or users who want to become more informed come to this forum hoping to gain an understanding, just to be let down by a few users who post with an overinflated sense of themselves. The unfortunate part is some of these users post on everything... Before Paul gets infuriated and comments on my post, I would like to say I know you. Paul is one of the few users who is a bit difficult to work and usually keeps me steered away from this forum.

Not to advertise or anything but I have found great Arduino resources on Instructables.com and http://www.circuitsathome.com. Both have knowledgeable members who do not try to inflame their own issues and agendas.

Paul, try to have some patience and compassion. People come here to learn.
He who dares, Wins.

PaulS

Quote
Paul, try to have some patience and compassion. People come here to learn.

The only way that can happen is for those people to admit that they might be doing something wrong, without getting defensive, and to be prepared to answer questions.
The art of getting good answers lies in asking good questions.

Bob808

Oh God, but ofcourse I don't understand something... That's why I posted here. Else I would just email the author that his library is broken :)))
I admit that I don't understand some things, or that I got them wrong.
Why would I post here?
The name of the thread implies it!
"Time and TimeAlarms Libraries - Ask here for help or suggestions "

UKHeliBob

It's time for everyone to take a deep breath and calm down.

He might not agree but PaulS can be abrasive at times, but he does know his stuff.  I think what come through is his frustration that people appear not to take note of his suggestions and comments.  Mind you, I know how he feels having suggested how to reset an alarm with new values with no sign that the OP has tried it.

So I suggest that we start again.  Please post your code as it currently stands, describe the problem and let's see if we can make some progress.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

cattledog

Bob 808--
I realize this thread involves time alarms, but I can see that you are not reading and writing your values to the eeprom correctly.

You are leaving out the I2C address of the eeprom. It is the addr in the Wire.beginTransmission line. There are two address to be concerned about, the device address of the eeprom, and the storage address within the eeprom(what you call eeaddress). From one of your earlier posts, it looks like the eeprom (24C32?) address is 0x52.

Additionally, the read EEPROM function should not be void, but have a byte return.

Code: [Select]
void writeEEPROM(unsigned int eeaddress, byte data)   //EEPROM write function
{
  Wire.beginTransmission(addr);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(data);
  Wire.endTransmission();
  delay(15);
}


Code: [Select]
void readEEPROM(unsigned int eeaddress)                //EEPROM read function
  {
  Wire.beginTransmission(addr);
  Wire.write((int)(eeaddress >> 8));
  Wire.write((int)(eeaddress & 0xFF));
  Wire.endTransmission();
  Wire.requestFrom(addr, 1);
  rec=Wire.read();
  }


These functions should be

Code: [Select]
void writeEEPROM(int addr, unsigned int eeaddress, byte data)   //EEPROM write function
{
  Wire.beginTransmission(addr);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(data);
  Wire.endTransmission();
  delay(15);


Code: [Select]
byte readEEPROM(int addr, unsigned int eeaddress)                //EEPROM read function
  {
  byte rec = 0;
  Wire.beginTransmission(addr);
  Wire.write((int)(eeaddress >> 8));
  Wire.write((int)(eeaddress & 0xFF));
  Wire.endTransmission();
  Wire.requestFrom(addr, 1);
  rec=Wire.read();
  return = rec;
  }


And when you call them you need to include all the parameters

Code: [Select]
readEEPROM (addr, eeaddress)
Code: [Select]
writeEEPROM(addr, eeaddress, data)

Bob808

Sorry, I was out and could only be bothered to answer to Paul :)
Let me catch up and be right back.
As a quick note, I see that indeed The read write functions do the job I need, they write on the eeprom, i delete the write function call, call the read function, re-upload the code and on serial monitor I get the previously written info.
So I presumed it works. Also addr is defined at the begining as 0x52. It is a 24lc256. I have another 24c32 on the i2c line soldered on the ds1307 pcb. Didn't want to use that one (has 0x50) as I might make a write loop by mistake and damage the chip. It's nice to have on the same pcb with the clock for further projects.

Bob808

Meanwhile here's my complete code. I used a few sketches while building various parts of the final code, like menu and eeprom management and alarms etc. So here's the complete code:

Code: [Select]
#include <Wire.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <DS1307RTC.h>
#include <LiquidCrystal.h>
#include "M2tk.h"
#include "utility/m2ghlc.h"

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

uint8_t uiKeySelectPin = A3;
int addr = 0x52;
const int light = 7;
byte rec,data;
int address,t,resethour,resetminute;

uint8_t t_hours = 0;
uint8_t t_minutes = 0;
uint8_t a_hours = 0;
uint8_t a_minutes = 0;

int  onH,onM,offH,offM =0;
static tmElements_t tm;
 

M2_EXTERN_HLIST(top_el_expandable_menu);
M2_LABEL(el_set_time, "x5y3", "Start Time:");
M2_LABEL(el_ht, "x3y2", "hour   -");
M2_U8NUM(el_t_hour, "x12y2c2", 0, 23, &t_hours);
M2_LABEL(el_mt, "x3y1", "minute -");
M2_U8NUM(el_t_minute, "x12y1c2", 0, 59, &t_minutes);
M2_BUTTON(el_set_t, "x3y0", "set", write_t_time);
M2_BUTTON(el_back_t, "x10y0", "back", fn_back);
M2_LIST(timelist) = {&el_set_time, &el_ht, &el_mt, &el_t_hour, &el_t_minute, &el_set_t, &el_back_t};
M2_XYLIST(el_set_Time, NULL, timelist);
M2_LABEL(el_set_alarm, "x5y3", "Stop Time:");
M2_LABEL(el_ah, "x3y2", "hour   -");
M2_U8NUM(el_a_hour, "x12y2c2", 0, 23, &a_hours);
M2_LABEL(el_am, "x3y1", "minute -");
M2_U8NUM(el_a_minute, "x12y1c2", 0, 59, &a_minutes);
M2_BUTTON(el_set_a, "x3y0", "set", write_a_time);
M2_BUTTON(el_back_a, "x10y0", "back", fn_back);
M2_LIST(alarmlist) = {&el_set_alarm, &el_ah, &el_am, &el_a_hour, &el_a_minute, &el_set_a, &el_back_a};
M2_XYLIST(el_set_Alarm, NULL, alarmlist);
m2_menu_entry m2_2lmenu_data[] =
{
  { "Set Light", NULL },
  { ". Start Time:", &el_set_Time },
  { ". Stop Time:", &el_set_Alarm },
  { NULL, NULL },
};
uint8_t m2_2lmenu_first;
uint8_t m2_2lmenu_cnt;
M2_2LMENU(el_2lmenu,"l4e1w12", NULL, &m2_2lmenu_cnt, m2_2lmenu_data, NULL, NULL, '\0');
M2_LIST(list_2lmenu) = { &el_2lmenu};
M2_HLIST(top_el_expandable_menu, NULL, list_2lmenu);
M2tk m2(&top_el_expandable_menu, m2_es_arduino_rotary_encoder, m2_eh_4bd, m2_gh_lc);

void setup () {
   
    Serial.begin(57600);
    Wire.begin();
    lcd.begin(20, 4);
    setSyncProvider(RTC.get);
     pinMode(light, OUTPUT);
     digitalWrite(light, LOW);
      m2_SetLiquidCrystal(&lcd, 20, 4);
      m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
      m2.setPin(M2_KEY_ROT_ENC_A, A0);
      m2.setPin(M2_KEY_ROT_ENC_B, A1);
    readEEPROM(0);         
    onH=rec;               
    readEEPROM(1);         
    onM=rec;               
    readEEPROM(2);         
    offH=rec;
    readEEPROM(3);       
    offM=rec;
     Alarm.alarmRepeat(onH, onM, 0, LightsOn);
     Alarm.alarmRepeat(offH, offM, 0, LightsOff);
    int resethour = hour();
    int resetminute = minute();
    if (onH < resethour && offH > resethour)
    {
      LightsOn();
    }
    else if (onH == resethour && onM <= resetminute)
    {
      if (offH == resethour && offM > resetminute)
       {
         LightsOn();
       }
     LightsOn();
   }
}

 
void loop () {
   m2.checkKey();
   m2.checkKey();
    if ( m2.handleKey() )
     m2.draw();
   m2.checkKey();
Alarm.delay(1);

}

void LightsOn() {                         // Set Lights On
digitalWrite(light, HIGH);
    Serial.println("Lights On");
}



void LightsOff() {                         // Set Lights Off
digitalWrite(light, LOW);
   Serial.println("Lights Off"); 
}


void writeEEPROM( unsigned int eeaddress, byte data)   //EEPROM write function
{
  Wire.beginTransmission(addr);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(data);
  Wire.endTransmission();
  delay(15);
}

void readEEPROM(unsigned int eeaddress)                //EEPROM read function
  {
  Wire.beginTransmission(addr);
  Wire.write((int)(eeaddress >> 8));
  Wire.write((int)(eeaddress & 0xFF));
  Wire.endTransmission();
  Wire.requestFrom(addr, 1);
  rec=Wire.read();
  }

void fn_back(m2_el_fnarg_p fnarg)   // back button
  {
    m2.setRoot(&top_el_expandable_menu);
  }
 
void write_t_time(m2_el_fnarg_p fnarg) // set ON time
  {
   writeEEPROM(0,t_hours);
   writeEEPROM(1,t_minutes);
   lcd.clear();
   lcd.setCursor(8,1);
   lcd.print("Set!");
   delay(1000);
  }

void write_a_time(m2_el_fnarg_p fnarg) // set OFF time
  {
   writeEEPROM(2,a_hours);
   writeEEPROM(3,a_minutes);
   lcd.clear();
   lcd.setCursor(8,1);
   lcd.print("Set!");
   delay(1000);
  }


This bit is the redundancy for power failure. I haven't figured it out completely but for start hour 00:00 and stop hour 01:00 and I reset it at 00:30 it works. I just tested it again, it works, it starts the alarm at boot, and stops on the clock. If start time is 00:05, and current time is 00:03, after boot, in 2 minutes the alarm triggers. The alarm times are ALL read out from the eeprom, the functions work, as they are defined now.

Code: [Select]
int resethour = hour();
    int resetminute = minute();
    if (onH < resethour && offH > resethour)
    {
      LightsOn();
    }
    else if (onH == resethour && onM <= resetminute)
    {
      if (offH == resethour && offM > resetminute)
       {
         LightsOn();
       }
     LightsOn();
   }



I'm not saying that it's better some other ways. I'm just saying that these are my results.
Also I have to look at the read function as it's declared void not byte. I still have a lot to learn.

The LCD menu library is m2tklib developed by olikraus member here on this forum. He's been a real gent in working with me to figure out the way it works, and I wrapped my head around most of the code that I use from his library.

Bob808

I tried it with Alarm.write but doesn't seem to work either. I'm calling it when I set the on/off times.

Code: [Select]
#include <Wire.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <DS1307RTC.h>
#include <LiquidCrystal.h>
#include "M2tk.h"
#include "utility/m2ghlc.h"

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

uint8_t uiKeySelectPin = A3;
int addr = 0x52;
const int light = 7;
byte rec,data;
int address,t,resethour,resetminute;

uint8_t t_hours = 0;
uint8_t t_minutes = 0;
uint8_t a_hours = 0;
uint8_t a_minutes = 0;

int  onH,onM,offH,offM =0;
static tmElements_t tm;

AlarmID_t on, off;  

M2_EXTERN_HLIST(top_el_expandable_menu);
M2_LABEL(el_set_time, "x5y3", "Start Time:");
M2_LABEL(el_ht, "x3y2", "hour   -");
M2_U8NUM(el_t_hour, "x12y2c2", 0, 23, &t_hours);
M2_LABEL(el_mt, "x3y1", "minute -");
M2_U8NUM(el_t_minute, "x12y1c2", 0, 59, &t_minutes);
M2_BUTTON(el_set_t, "x3y0", "set", write_t_time);
M2_BUTTON(el_back_t, "x10y0", "back", fn_back);
M2_LIST(timelist) = {&el_set_time, &el_ht, &el_mt, &el_t_hour, &el_t_minute, &el_set_t, &el_back_t};
M2_XYLIST(el_set_Time, NULL, timelist);
M2_LABEL(el_set_alarm, "x5y3", "Stop Time:");
M2_LABEL(el_ah, "x3y2", "hour   -");
M2_U8NUM(el_a_hour, "x12y2c2", 0, 23, &a_hours);
M2_LABEL(el_am, "x3y1", "minute -");
M2_U8NUM(el_a_minute, "x12y1c2", 0, 59, &a_minutes);
M2_BUTTON(el_set_a, "x3y0", "set", write_a_time);
M2_BUTTON(el_back_a, "x10y0", "back", fn_back);
M2_LIST(alarmlist) = {&el_set_alarm, &el_ah, &el_am, &el_a_hour, &el_a_minute, &el_set_a, &el_back_a};
M2_XYLIST(el_set_Alarm, NULL, alarmlist);
m2_menu_entry m2_2lmenu_data[] =
{
 { "Set Light", NULL },
 { ". Start Time:", &el_set_Time },
 { ". Stop Time:", &el_set_Alarm },
 { NULL, NULL },
};
uint8_t m2_2lmenu_first;
uint8_t m2_2lmenu_cnt;
M2_2LMENU(el_2lmenu,"l4e1w12", NULL, &m2_2lmenu_cnt, m2_2lmenu_data, NULL, NULL, '\0');
M2_LIST(list_2lmenu) = { &el_2lmenu};
M2_HLIST(top_el_expandable_menu, NULL, list_2lmenu);
M2tk m2(&top_el_expandable_menu, m2_es_arduino_rotary_encoder, m2_eh_4bd, m2_gh_lc);

void setup () {
   
   Serial.begin(57600);
   Wire.begin();
   lcd.begin(20, 4);
   setSyncProvider(RTC.get);
    pinMode(light, OUTPUT);
    digitalWrite(light, LOW);
     m2_SetLiquidCrystal(&lcd, 20, 4);
     m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
     m2.setPin(M2_KEY_ROT_ENC_A, A0);
     m2.setPin(M2_KEY_ROT_ENC_B, A1);
   readEEPROM(addr,0);          
   onH=rec;                
   readEEPROM(addr,1);        
   onM=rec;                
   readEEPROM(addr,2);        
   offH=rec;
   readEEPROM(addr,3);        
   offM=rec;
   on = Alarm.alarmRepeat(onH, onM, 0, LightsOn);
   off = Alarm.alarmRepeat(offH, offM, 0, LightsOff);
time_t newTime = AlarmHMS(onH,onM,00);
Alarm.write(on,newTime);

   int resethour = hour();
   int resetminute = minute();
   if (onH < resethour && offH > resethour)
   {
     LightsOn();
   }
   else if (onH == resethour && onM <= resetminute)
   {
     if (offH == resethour && offM > resetminute)
      {
        LightsOn();
      }
    LightsOn();
  }
}

 
void loop () {
  m2.checkKey();
  m2.checkKey();
   if ( m2.handleKey() )
    m2.draw();
  m2.checkKey();
Alarm.delay(1);

}

void LightsOn() {                         // Set Lights On
digitalWrite(light, HIGH);
   Serial.println("Lights On");
}



void LightsOff() {                         // Set Lights Off
digitalWrite(light, LOW);
  Serial.println("Lights Off");  
}


void writeEEPROM(int addr, unsigned int eeaddress, byte data)   //EEPROM write function
{
 Wire.beginTransmission(addr);
 Wire.write((int)(eeaddress >> 8));   // MSB
 Wire.write((int)(eeaddress & 0xFF)); // LSB
 Wire.write(data);
 Wire.endTransmission();
 delay(15);
}

byte readEEPROM(int addr, unsigned int eeaddress)                //EEPROM read function
 {
 Wire.beginTransmission(addr);
 Wire.write((int)(eeaddress >> 8));
 Wire.write((int)(eeaddress & 0xFF));
 Wire.endTransmission();
 Wire.requestFrom(addr, 1);
 rec=Wire.read();
 }

void fn_back(m2_el_fnarg_p fnarg)   // back button
 {
   m2.setRoot(&top_el_expandable_menu);
 }
 
void write_t_time(m2_el_fnarg_p fnarg) // set ON time
 {
  writeEEPROM(addr,0,t_hours);
  writeEEPROM(addr,1,t_minutes);
   readEEPROM(addr,0);          
   onH=rec;                
   readEEPROM(addr,1);        
   onM=rec;                
  time_t newTime = AlarmHMS(onH,onM,00);
  Alarm.write(on,newTime);
  Serial.print("On:");
  Serial.print(onH);
  Serial.print(":");
  Serial.println(onM);
  lcd.clear();
  lcd.setCursor(8,1);
  lcd.print("Set!");
  delay(1000);
 }

void write_a_time(m2_el_fnarg_p fnarg) // set OFF time
 {
  writeEEPROM(addr,2,a_hours);
  writeEEPROM(addr,3,a_minutes);
  readEEPROM(addr,2);          
   offH=rec;                
   readEEPROM(addr,3);        
   offM=rec;                
  time_t newTimea = AlarmHMS(offH,offM,00);
  Alarm.write(off,newTimea);
  Serial.print("Off:");
  Serial.print(offH);
  Serial.print(":");
  Serial.println(offM);
  lcd.clear();
  lcd.setCursor(8,1);
  lcd.print("Set!");
  delay(1000);
 }
 



Serial.print is there so I see that the values were stored&read from the eeprom when I set the times.


Bob808

#293
Sep 17, 2014, 02:05 am Last Edit: Sep 17, 2014, 02:22 am by Bob808 Reason: 1
Made something else, I found some code that mem wrote, to print on serial the current time and the time that the alarms are set.
I put that in loop, and watched the serial monitor as time went by.
If I boot the arduino with 1 minute before ON time then the alarm fires properly. If I set the time from the menu with 1-2 minutes before I set it to fire, it does NOT fire. To see if the alarms get updated, I put this code so I can check what's happening, if the alarms are getting updated.

This is the complete code used:
Code: [Select]
#include <Wire.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <DS1307RTC.h>
#include <LiquidCrystal.h>
#include "M2tk.h"
#include "utility/m2ghlc.h"

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

uint8_t uiKeySelectPin = A3;
int addr = 0x52;
const int light = 7;
byte rec,data;
int address,t,resethour,resetminute;

uint8_t t_hours = 0;
uint8_t t_minutes = 0;
uint8_t a_hours = 0;
uint8_t a_minutes = 0;

int  onH,onM,offH,offM =0;
static tmElements_t tm;

AlarmID_t on, off;  

M2_EXTERN_HLIST(top_el_expandable_menu);
M2_LABEL(el_set_time, "x5y3", "Start Time:");
M2_LABEL(el_ht, "x3y2", "hour   -");
M2_U8NUM(el_t_hour, "x12y2c2", 0, 23, &t_hours);
M2_LABEL(el_mt, "x3y1", "minute -");
M2_U8NUM(el_t_minute, "x12y1c2", 0, 59, &t_minutes);
M2_BUTTON(el_set_t, "x3y0", "set", write_t_time);
M2_BUTTON(el_back_t, "x10y0", "back", fn_back);
M2_LIST(timelist) = {&el_set_time, &el_ht, &el_mt, &el_t_hour, &el_t_minute, &el_set_t, &el_back_t};
M2_XYLIST(el_set_Time, NULL, timelist);
M2_LABEL(el_set_alarm, "x5y3", "Stop Time:");
M2_LABEL(el_ah, "x3y2", "hour   -");
M2_U8NUM(el_a_hour, "x12y2c2", 0, 23, &a_hours);
M2_LABEL(el_am, "x3y1", "minute -");
M2_U8NUM(el_a_minute, "x12y1c2", 0, 59, &a_minutes);
M2_BUTTON(el_set_a, "x3y0", "set", write_a_time);
M2_BUTTON(el_back_a, "x10y0", "back", fn_back);
M2_LIST(alarmlist) = {&el_set_alarm, &el_ah, &el_am, &el_a_hour, &el_a_minute, &el_set_a, &el_back_a};
M2_XYLIST(el_set_Alarm, NULL, alarmlist);
m2_menu_entry m2_2lmenu_data[] =
{
 { "Set Light", NULL },
 { ". Start Time:", &el_set_Time },
 { ". Stop Time:", &el_set_Alarm },
 { NULL, NULL },
};
uint8_t m2_2lmenu_first;
uint8_t m2_2lmenu_cnt;
M2_2LMENU(el_2lmenu,"l4e1w12", NULL, &m2_2lmenu_cnt, m2_2lmenu_data, NULL, NULL, '\0');
M2_LIST(list_2lmenu) = { &el_2lmenu};
M2_HLIST(top_el_expandable_menu, NULL, list_2lmenu);
M2tk m2(&top_el_expandable_menu, m2_es_arduino_rotary_encoder, m2_eh_4bd, m2_gh_lc);

void setup () {
   
   Serial.begin(57600);
   Wire.begin();
   lcd.begin(20, 4);
   setSyncProvider(RTC.get);
    pinMode(light, OUTPUT);
    digitalWrite(light, LOW);
     m2_SetLiquidCrystal(&lcd, 20, 4);
     m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
     m2.setPin(M2_KEY_ROT_ENC_A, A0);
     m2.setPin(M2_KEY_ROT_ENC_B, A1);
   readEEPROM(addr,0);          
   onH=rec;                
   readEEPROM(addr,1);        
   onM=rec;                
   readEEPROM(addr,2);        
   offH=rec;
   readEEPROM(addr,3);        
   offM=rec;
   on = Alarm.alarmRepeat(onH, onM, 0, LightsOn);
   off = Alarm.alarmRepeat(offH, offM, 0, LightsOff);
//time_t newTime = AlarmHMS(onH,onM,00);
//Alarm.write(on,newTime);
/*
   int resethour = hour();
   int resetminute = minute();
   if (onH < resethour && offH > resethour)
   {
     LightsOn();
   }
   else if (onH == resethour && onM <= resetminute)
   {
     if (offH == resethour && offM > resetminute)
      {
        LightsOn();
      }
    LightsOn();
  }
*/
}

 
void loop () {
  m2.checkKey();
  m2.checkKey();
   if ( m2.handleKey() )
    m2.draw();
  m2.checkKey();
  time_t t = now();
 digitalClockDisplay(t);
 Alarm.delay(10); // wait one second between clock display
 showAlarmTime(on);
 showAlarmTime(off);

//Alarm.delay(1);

}

void LightsOn() {                         // Set Lights On
digitalWrite(light, HIGH);
   Serial.println("Lights On");
}



void LightsOff() {                         // Set Lights Off
digitalWrite(light, LOW);
  Serial.println("Lights Off");  
}


void writeEEPROM(int addr, unsigned int eeaddress, byte data)   //EEPROM write function
{
 Wire.beginTransmission(addr);
 Wire.write((int)(eeaddress >> 8));   // MSB
 Wire.write((int)(eeaddress & 0xFF)); // LSB
 Wire.write(data);
 Wire.endTransmission();
 delay(15);
}

byte readEEPROM(int addr, unsigned int eeaddress)                //EEPROM read function
 {
 Wire.beginTransmission(addr);
 Wire.write((int)(eeaddress >> 8));
 Wire.write((int)(eeaddress & 0xFF));
 Wire.endTransmission();
 Wire.requestFrom(addr, 1);
 rec=Wire.read();
 }

void fn_back(m2_el_fnarg_p fnarg)   // back button
 {
   m2.setRoot(&top_el_expandable_menu);
 }
 
void write_t_time(m2_el_fnarg_p fnarg) // set ON time
 {
  writeEEPROM(addr,0,t_hours);
  writeEEPROM(addr,1,t_minutes);
   readEEPROM(addr,0);          
   onH=rec;                
   readEEPROM(addr,1);        
   onM=rec;                
  time_t newTime = AlarmHMS(onH,onM,0);
  Alarm.write(on,newTime);
 // Alarm.disable (on);  
//  Alarm.free (on);
  Serial.print("On:");
  Serial.print(onH);
  Serial.print(":");
  Serial.println(onM);
  lcd.clear();
  lcd.setCursor(8,1);
  lcd.print("Set!");
  delay(1000);
 }

void write_a_time(m2_el_fnarg_p fnarg) // set OFF time
 {
  writeEEPROM(addr,2,a_hours);
  writeEEPROM(addr,3,a_minutes);
  readEEPROM(addr,2);          
   offH=rec;                
   readEEPROM(addr,3);        
   offM=rec;                
  time_t newTimea = AlarmHMS(offH,offM,0);
  Alarm.write(off,newTimea);
 // Alarm.disable (off);  
 // Alarm.free (off);
  Serial.print("Off:");
  Serial.print(offH);
  Serial.print(":");
  Serial.println(offM);
  lcd.clear();
  lcd.setCursor(8,1);
  lcd.print("Set!");
  delay(1000);
 }
 
void showAlarmTime(AlarmID_t id)
{
 time_t alarmTime = Alarm.read(id);
 if(alarmTime!= 0)
 {
   if( alarmTime <= SECS_PER_DAY)  
      Serial.print(" repeat alarm with ID ");
   else  
       Serial.print(" once only alarm with ID  ");
   Serial.print(id, DEC);    
   Serial.print(" set for ");
   digitalClockDisplay(alarmTime);
 }  
}


void digitalClockDisplay(time_t t)
{
 // digital clock display of the time
 Serial.print(hour(t));
 printDigits(minute(t));
 printDigits(second(t));
 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);
}


So basically I could see on the serial monitor live, as I set the alarm times from the menu, they were reflected instantly on screen.
But when the time came, the alarms did NOT fire. Besides the LED no lighting up, I also have a serial message from the function that the alarm calls. That didn't came up either.
I attached the output of mem's code:

Code: [Select]
2:52:59
repeat alarm with ID 0 set for 2:53:00
repeat alarm with ID 1 set for 2:54:00
2:53:00
repeat alarm with ID 0 set for 2:53:00
repeat alarm with ID 1 set for 2:54:00
2:53:01
repeat alarm with ID 0 set for 2:53:00
repeat alarm with ID 1 set for 2:54:00



So now I can see clearly that the alarms are getting updated, what is going on?
If I set the alarms from the menu, let's say 2 minutes ahead of present time, and I reset the board, the alarms fire. And this is interesting, check the serial output:
Code: [Select]
3:03:59
repeat alarm with ID 0 set for 3:04:00
repeat alarm with ID 1 set for 3:05:00
3:03:59
Lights On
repeat alarm with ID 0 set for 3:04:00
repeat alarm with ID 1 set for 3:05:00
3:04:00
repeat alarm with ID 0 set for 3:04:00
repeat alarm with ID 1 set for 3:05:00

I get the message that the alarm has been triggered (as in, the function that the alarm triggers).
So now I need help :)
Paul?


//later edit:
also if I remove Alarm.write from the set time functions and I add it to loop() I get the same results.
Code: [Select]
void loop ()
{
..................................................................................................
    readEEPROM(addr,0);         
    onH=rec;               
    readEEPROM(addr,1);         
    onM=rec;               
    readEEPROM(addr,2);         
    offH=rec;
    readEEPROM(addr,3);       
    offM=rec;
time_t newTime = AlarmHMS(onH,onM,00);
time_t newTimea = AlarmHMS(offH,offM,00);
Alarm.write(on,newTime);
Alarm.write(off,newTimea);
..................................................................................................
}


PaulS


Anyone have any ideas?

You know what time it is. You know when you want things to happen. Do you really need a library to make that happen for you?
The art of getting good answers lies in asking good questions.

Bob808

Well, I went the library way at first as I didn't know any other way. I guess I will try setting the time and just if/then/else?

PaulS

Quote
I guess I will try setting the time and just if/then/else?

then? This isn't Basic.

But, yeah, that's the simplest way.
The art of getting good answers lies in asking good questions.

Bob808

Great, thx.
I'll try it and come back with my results.
Although I guess it would be interesting to hear mem's opinion on my results with TimeAlarm library.

Bob808

#299
Sep 17, 2014, 11:57 pm Last Edit: Sep 18, 2014, 12:01 am by Bob808 Reason: 1
I removed the whole alarms deal from my code.
Just added this to loop:
Code: [Select]
readEEPROM(addr,0);          
   onH=rec;                
   readEEPROM(addr,1);        
   onM=rec;                
   readEEPROM(addr,2);        
   offH=rec;
   readEEPROM(addr,3);        
   offM=rec;
   int nowh = hour();
    int nowm = minute();
    int nows = second();
  if (nowh == onH && nowm == onM && nows == 0)
  {
    LightsOn();
  }
 
  if (nowh == offH && nowm == offM && nows == 0)
  {
    LightsOff();
 
 }


Second is defined because I need it to trigger on exact time but not run the function for a whole minute, instead it calls it for a second that way.
Now I just need to make the if statements for redundancy,  and with hour and minutes values it's going to get a bit messy.

Go Up