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.
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
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.
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.
@ 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:
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