Go Down

Topic: Can't complile TimeAlarm library without getting error Alarm out of scope (Read 2 times) previous topic - next topic

DadEE

Hello,
I am having problems using the Time and TimeAlarm libraries with my Arduino UNO and a Macintosh power book. I am not a programmer, but I have googled the forums etc to try to find solutions to my problem, to no avail.d

Specifically, when I try to compile the TimeAlarmExample that came along with the TimeAlarm library that I downloaded, I keep getting the error message: "  'Alarm' was not declared in this scope" . I have tried the following:
1.   made sure that the TimeAlarm.cpp and TimeAlarm.h files are in my "Libraries" folder for Arduino, not nested in other folders.
2.   Used textedit to check the cpp file to make sure it is updated to call Arduino.h instead of WProgram.h.
3.   Changed the brackets (ie, <>) around the library calls to quotes (ie, " "), for example: #include <Time.h>  becomes #include "Time.h"
4.   I went into the TimeAlarms cpp file and could not find an "alarm" definition, but I did find AlarmID_t. I tried changing the example sketch to use AlarmID_t instead of alarm, but this did not work either (perhaps I don't understand the syntax?)
In what may be a related problem, in trying to run any of the time related example scripts, I notice that the serial monitor gets the message "waiting for sync message", which makes me think the UNO is NOT getting a synch message from my Mac. This makes me wonder if for some reason neither the time nor timealarms libraries are being loaded and/or recognized correctly.

Can anyone make a suggestion to solve these problems? Following is the example TimeAlarmExample sketch that I am trying to run:

Code: [Select]

/*
* TimeAlarmExample.pde
*
* This example calls alarm functions at 8:30 am and at 5:45 pm (17:45)
* and simulates turning lights on at night and off in the morning
* A weekly timer is set for Saturdays at 8:30:30
*
* A timer is called every 15 seconds
* Another timer is called once only after 10 seconds
*
* At startup the time is set to Jan 1 2011  8:29 am
*/

#include "Time.h"
#include "TimeAlarms.h"

void setup()
{
  Serial.begin(9600);
  setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011
  // create the alarms
  Alarm.alarmRepeat(8,30,0, MorningAlarm);  // 8:30am every day
  Alarm.alarmRepeat(17,45,0,EveningAlarm);  // 5:45pm every day
  Alarm.alarmRepeat(dowSaturday,8,30,30,WeeklyAlarm);  // 8:30:30 every Saturday


  Alarm.timerRepeat(15, Repeats);            // timer for every 15 seconds   
  Alarm.timerOnce(10, OnceOnly);             // called once after 10 seconds
}

void  loop(){ 
  digitalClockDisplay();
  Alarm.delay(1000); // wait one second between clock display
}

// functions to be called when an alarm triggers:
void MorningAlarm(){
  Serial.println("Alarm: - turn lights off");   
}

void EveningAlarm(){
  Serial.println("Alarm: - turn lights on");           
}

void WeeklyAlarm(){
  Serial.println("Alarm: - its Monday Morning");     
}

void ExplicitAlarm(){
  Serial.println("Alarm: - this triggers only at the given date and time");       
}

void Repeats(){
  Serial.println("15 second timer");         
}

void OnceOnly(){
  Serial.println("This timer only triggers once"); 
}

void digitalClockDisplay()
{
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println();
}

void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}




Thanks.

WizenedEE


1.   made sure that the TimeAlarm.cpp and TimeAlarm.h files are in my "Libraries" folder for Arduino, not nested in other folders.


1) They should be in the "libraries" directory
2) They should be in a directory in the "libraries" directory named "TimeAlarm"

So it should be
Code: [Select]

sketchbook
--<other sketches>
--libraries
----TimeAlarm
------TimeAlarm.h
------TimeAlarm.cpp
----<other libraries>

DadEE

Thank you to WizenedEE for your quick response. Using nested folders seems to have worked and the TimeAlarmsExample sketch seems to work correctly.

I also created a nested folder for the Time library, but when I run the TimeSerialDateStrings example sketch, the Arduino never grabs the time from my Mac. The sketch compiles and loads ok, but the serial monitor just gets the message "waiting for sync message" . I have made two modifications to the example sketch that I saw suggested in the forums:
1.   Changed the brackets (ie, <>) around the library calls to quotes (ie, " "), for example: #include <Time.h>  becomes #include "Time.h"
2.   Replaced the outdated Serial.print(TIME_REQUEST,BYTE); with Serial.write(TIME_REQUEST)
I see that the "definition" of setSyncProvider is in Time.cpp, but this compiles so I don't know why the function is not grabbing the system time from my Mac.

Can anyone suggest a fix? I would like to be able to grab the full time, day, date info from the Mac, and eventually other info through the serial port (like emails, weather, etc), so I want to understand how to get the Arduino and Mac talking through the serial port.

Thanks.

MarkT

The meaning of <> quotes in includes is "look in the standard places" - ie the libraries directory and built-in libraries.

The "" quotes in includes means "look in the same directory as this file, and if that fails look in standard places".

The latter means you can have your own .h files that accidentally name-clash with system libraries without having
to rename them.
[ I won't respond to messages, use the forum please ]

PaulS

Quote
I see that the "definition" of setSyncProvider is in Time.cpp, but this compiles so I don't know why the function is not grabbing the system time from my Mac.

What is running on the Mac that is listening to the serial port? Nothing happens by magic.

Go Up