Using TimeAlarm library to trigger blink at a certain time

Hi, this is my first step into Arduino and micro controllers. I do have C# experience, but the Arduino code is kind of throwing me of. Anyway, I want my arduino to trigger blink at a specific time. Here is my code:

#include <Time.h>
#include <TimeAlarms.h>
int led = 2;

void setup()
{
  Serial.begin(9600);
  setTime(9,15,0,8,11,12); // set time to Saturday 8:29:00am Jan 1 2011
  Alarm.alarmRepeat(5, 45, 0, MorningAlarm);
  pinMode(led, OUTPUT);

}


void MorningAlarm()
{
 Serial.println("Wake UP");
 digitalWrite (led, HIGH);  
 delay(1000);
 digitalWrite (led, LOW);
 delay(1000);
}

I get this error message:
C:\Users\John\Desktop\arduino-1.0.1\libraries\TimeAlarms\TimeAlarms.cpp: In member function 'void TimeAlarmsClass::delay(long unsigned int)':
C:\Users\John\Desktop\arduino-1.0.1\libraries\TimeAlarms\TimeAlarms.cpp:256: error: 'millis' was not declared in this scope

What is the problem? I installed the Time library and all the libraries in it. Thanks for helping me out.

Let's start with the basics. What version of the IDE are you using? 1.0.1 has a fatal flaw, in my opinion, in which missing include files are not fatal errors.

Hi, where does one find the TimeAlarms library? Been searching the arduino site but no luck.
Many thanks in advance!

Hi, where does one find the TimeAlarms library? Been searching the arduino site but no luck.

What have you been searching for?

http://arduino.cc/playground/Code/Time

Oddly, while the Time library was updated for Arduino 1.0 and later, TimeAlarms was not. Replace the TimeAlarms.cpp file with the one attached.

Your sketch also needs the loop() function defined. Every Arduino sketch needs setup() and loop() defined, even if they are empty.

TimeAlarms.cpp (12.8 KB)

I've tried the file that Jack Christensen posted, but I still get the following:
C:\arduino-1.0.1\libraries\TimeAlarms\TimeAlarms.cpp: In member function 'void TimeAlarmsClass::delay(long unsigned int)':
C:\arduino-1.0.1\libraries\TimeAlarms\TimeAlarms.cpp:256: error: 'millis' was not declared in this scope. I'm using the stock unchanged example "TimeAlarmExample". I'm running 1.0.1. Getting really frustrated. :0

I just double-checked using the following procedure, also using Arduino 1.0.1.

  1. Shut down the IDE.
  2. Delete Time, TimeAlarms, DS1307RTC libraries.
  3. Download Time.zip from Arduino Playground - Time and unzip.
  4. Start IDE, compile "TimeAlarmExample" ... duplicates the error messages as above.
  5. Shut down IDE.
  6. Download TimeAlarms.cpp from the post above, replace the existing file in the library with it.
  7. Start IDE, compile "TimeAlarmExample" ... compiles OK.

I know that no one likes to hear "NTF" but if I can't duplicate the problem...

Jack,
I'm at a loss. I took line 256 from TimeAlarms.cpp and put it in a blank sketch with the setup and void loop, and it compiles fine? I'll have to try it on my laptop and see if I get the same error. I have started and restarted, deleted and reinstalled on desktop cpu. and can't get rid of the error.
Mark

fairwindsii:
I took line 256 from TimeAlarms.cpp and put it in a blank sketch with the setup and void loop, and it compiles fine?

Huh? What's on that line, and why would you do that? Line 256 in TimeAlarms.cpp is a blank line in my copy. Did you follow the procedure in my previous post, verbatim?

Edit: Oh sorry, line 256 is blank in my modified version, but not in the original. Anyway, I don't see where doing that is appropriate, so same answer, follow the procedure above. Delete the libraries, download an install fresh copies, then replace the TimeAlarms.cpp file with my modified version.

Hey Jack,
Tried it on the laptop; same thing.
The reason that I moved the line to a basic sketch with nothing else was to verify that millis() is defined. I'm going to do a complete new install of the ide and libs.

Mark

Ah, ok, so millis() works in other circumstances. Any chance that the new version of TimeAlarms.cpp is not getting saved in the right place? If line 256 was not blank, then that's not my updated copy. There could be other things I suppose, but those symptoms are consistent with the original TimeAlarms.cpp from the zip file being used.

Hi Jack,
Did a complete install of the ide and the time lib, along with the updated file from you.
It now works. Not sure what was wrong (probably me....I mean most likely me. We know it couldn't be Windows).
Now I need to load my other libs one at a time and make sure that it doesn't corrupt anything.

Thanks, Mark

Hey Mark,

Cool! Yeah with Windoze involved we'll cut ya some slack :smiley:

Have fun ... jc

can you post/share the updated file? I have the same issue re install did not work for me, tested on 2 machines.

thanks

Jasper

Gh3kko:
can you post/share the updated file? I have the same issue re install did not work for me, tested on 2 machines.

thanks

Jasper

Look up ... it's still there:

Haha, my bad, i'll blame the small font i use... Thanks, appreciated.

@ Jack Christensen
Sorry to bother, i feel kinda foolish asking this but i am lost at the moment. I too am trying to use the TimeAlarm library and i have replaced the .cpp file with your .cpp file (as mention in your post). However i am still getting an error. It says that the variables are not declared? The i am on Windows 7, Arduino 1.0.5.
The error message i am getting is:

TimeAlarmExample.pde: In function 'void setup()':
TimeAlarmExample:20: error: 'setTime' was not declared in this scope
TimeAlarmExample:22: error: 'Alarm' was not declared in this scope
TimeAlarmExample:24: error: 'dowSaturday' was not declared in this scope
TimeAlarmExample.pde: In function 'void loop()':
TimeAlarmExample:33: error: 'Alarm' was not declared in this scope
TimeAlarmExample.pde: In function 'void digitalClockDisplay()':
TimeAlarmExample:64: error: 'hour' was not declared in this scope
TimeAlarmExample:65: error: 'minute' was not declared in this scope
TimeAlarmExample:66: error: 'second' was not declared in this scope

Hope i provided enough information.
Thanks so much for your time

Looks like the library is installed in the wrong place. There is a known issue if the IDE's automatic installation process (Sketch > Import Library > Add Library) is used to install the Time library. The automatic process will install the three libraries that are in the Time.zip file as:

arduino\sketchbook\libraries\Time\DS1307RTC
arduino\sketchbook\libraries\Time\Time
arduino\sketchbook\libraries\Time\TimeAlarms

But they should be:

arduino\sketchbook\libraries\DS1307RTC
arduino\sketchbook\libraries\Time
arduino\sketchbook\libraries\TimeAlarms

Verify that they're in the right place, move them around if not.

Thanks
wil try that as soon as i can and let you know, how it goes.
Thanks for your quick response

Jack!!!!!!
you were spot on thanks so much!!! Finally i can sleep at ease.
The TimeAlarm and Time libraries were in in subfolders also called TimeAlarm and Time respectively.
Just copied sub folder and merged with parent folder
Once again thanks so much