Go Down

Topic: Alarm (Read 11846 times) previous topic - next topic

cne

Hi,

I am making a alarm that will go off several times a day.
The time is syncronized by a one second pulse at midnight.
It is based on the Time/TimeAlarms library.
I have wrote the software, but I am getting the following errors

Here is the code:

Code: [Select]
//This program recieves a 1 second pulse at middnight for syncronization
//Alarms are referenced off that event
//The alarms sound a buzzer for one second on pin 13
//The circuit recieves a pulse on pin 2

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

const int midnightPin= 2;
const int timerPin= 13;


int midnightState=0;

void setup()
{
 pinMode(midnightPin, INPUT);
 pinMode(timerPin, OUTPUT);
 
 Alarm.alarmRepeat(8,45,0,MeetingTwo);
 Alarm.alarmRepeat(9,00,0,MeetingThree);
 Alarm.alarmRepeat(9,15,0,MeetingFour);
 Alarm.alarmRepeat(9,30,0,MeetingFive);
 Alarm.alarmRepeat(10,00,0,MeetingSix);
 Alarm.alarmRepeat(10,30,0,MeetingSeven);
 Alarm.alarmRepeat(11,00,0,MeetingEight);
 Alarm.alarmRepeat(15,00,0,MeetingNine);
 
}

void MeetingOne()
{
 if (timeSet) {  //checks to see if time has been set
 digitalWrite(timerPin, HIGH);  //turns the buzzer on
 Alarm.delay(1000);  //waits one second
 digitalWrite(timerPin, LOW);  //turns the buzzer off
 }    
}

void MeetingTwo()
{
if (timeSet) {
 digitalWrite(timerPin, HIGH);
 Alarm.delay(1000);
 digitalWrite(timerPin, LOW);
 }              
}

void MeetingThree()
{
if (timeSet) {
 digitalWrite(timerPin, HIGH);
 Alarm.delay(1000);
 digitalWrite(timerPin, LOW);
 }            
}

void MeetingFour()
{
if (timeSet) {
 digitalWrite(timerPin, HIGH);
 Alarm.delay(1000);
 digitalWrite(timerPin, LOW);
 }    
}

void MeetingFive()
{
if (timeSet) {
 digitalWrite(timerPin, HIGH);
 Alarm.delay(1000);
 digitalWrite(timerPin, LOW);
 }    
}

void MeetingSix()
{
if (timeSet) {
 digitalWrite(timerPin, HIGH);
 Alarm.delay(1000);
 digitalWrite(timerPin, LOW);
 }    
}

void MeetingSeven()
{
if (timeSet) {
 digitalWrite(timerPin, HIGH);
 Alarm.delay(1000);
 digitalWrite(timerPin, LOW);
 }    
}

void MeetingEight()
{
if (timeSet) {
 digitalWrite(timerPin, HIGH);
 Alarm.delay(1000);
 digitalWrite(timerPin, LOW);
 }    
}

void MeetingNine()
{
if (timeSet) {
 digitalWrite(timerPin, HIGH);
 Alarm.delay(1000);
 digitalWrite(timerPin, LOW);
 }    
}

void  loop()
{
midnightState = digitalRead(midnightPin);  //reads the pulse
 if (midnightState == HIGH) {  
   setTime(23,59,0,1,1,10);  //sets time to one second before midnight
 }
}




Code: [Select]
In function `loop':
undefined reference to `setTime(int, int, int, int, int, int)'

o: In function `MeetingNine()':
undefined reference to `Alarm'

undefined reference to `Alarm'
undefined reference to `TimeAlarmsClass::delay(unsigned long)'

o: In function `MeetingEight()':
undefined reference to `Alarm'
undefined reference to `Alarm'
undefined reference to `TimeAlarmsClass::delay(unsigned long)'

o: In function `MeetingSeven()':
undefined reference to `Alarm'
undefined reference to `Alarm'

undefined reference to `TimeAlarmsClass::delay(unsigned long)'

o: In function `MeetingSix()':
undefined reference to `Alarm'
undefined reference to `Alarm'

undefined reference to `TimeAlarmsClass::delay(unsigned long)'

o: In function `MeetingFive()':
undefined reference to `Alarm'
undefined reference to `Alarm'
undefined reference to `TimeAlarmsClass::delay(unsigned long)'

o: In function `MeetingFour()':
undefined reference to `Alarm'

undefined reference to `Alarm'

undefined reference to `TimeAlarmsClass::delay(unsigned long)'

o: In function `MeetingThree()':
: undefined reference to `Alarm'

unundefined reference to `TimeAlarmsClass::delay(unsigned long)'

o: In function `MeetingTwo()':
undefined reference to `Alarm'

undefined reference to `Alarm'

undefined reference to `TimeAlarmsClass::delay(unsigned long)'

o: In function `setup':
undefined reference to `Alarm'
undefined reference to `Alarm'
undefined reference to `TimeAlarmsClass::alarmRepeat(int, int, int, void (*)())'
undefined reference to `TimeAlarmsClass::alarmRepeat(int, int, int, void (*)())'
undefined reference to `TimeAlarmsClass::alarmRepeat(int, int, int, void (*)())'
undefined reference to `TimeAlarmsClass::alarmRepeat(int, int, int, void (*)())'
undefined reference to `TimeAlarmsClass::alarmRepeat(int, int, int, void (*)())'

more undefined references to `TimeAlarmsClass::alarmRepeat(int, int, int, void (*)())' follow

AWOL

I don't see an "Alarm" object.

cne

Sorry, this could be a silly question,
But what is an alarm object?

cne

The code does contain this:

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


PaulS

Code: [Select]
Alarm.alarmRepeat(8,45,0,MeetingTwo);


This code is calling the alarmRepeat method of the Alarm object, which does not exist.

You have not created an instance of the Alarm class. That instance of the Alarm class is referred to as an object.

You need to do something like this:

Code: [Select]
Alarm noisyDamnClock;

void setup()
{
  noisyDamnClock.alarmRepeat(8, 45, 0, BoringMeeting);
}
The art of getting good answers lies in asking good questions.

mistergreen

#5
Mar 24, 2010, 03:33 pm Last Edit: Mar 24, 2010, 03:45 pm by mistergreen Reason: 1
Thanks, I was tearing my hair out about this as well but on a different issue. The certain alarm doesn't trigger . It's odd that it works in the example given. No mention of an instance was used. Here's the code of the example given:

I assumed Alarm is an instance defined in TimeAlarms.h etc...
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 timer is called every 15 seconds
* Another timer is called once only after 10 seconds
*
* At startup the time is set to Jan 1 2010  8:29 am
*/

#include <Time.h>
#include <TimeAlarms.h>

void setup()
{
 Serial.begin(9600);    
 Serial.println("TimeAlarms Example");
 Serial.println("Alarms are triggered daily at 8:30 am and 17:45 pm");
 Serial.println("One timer is triggered every 15 seconds");
 Serial.println("Another timer is set to trigger only once after 10 seconds");
 Serial.println();
 
 setTime(8,29,40,1,1,10); // set time to 8:29:40am Jan 1 2010

 Alarm.alarmRepeat(8,30,0, MorningAlarm);  // 8:30am every day
 Alarm.alarmRepeat(17,45,0,EveningAlarm);  // 5:45pm every day

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

void MorningAlarm()
{
 Serial.println("Alarm: - turn lights off");    
}

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

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

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

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

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



mistergreen

make sure the Time library is in your libraries folder, perhaps.

cne

Code: [Select]
error: 'Alarm' does not name a type In function 'void setup()':


I tried to add an object like this:
but I am still getting an error

Code: [Select]
Alarm noisydarnClock;

void setup()
{
 
 pinMode(midnightPin, INPUT);
 pinMode(timerPin, OUTPUT);
 
 noisydarnClock.alarmRepeat(0,00,10,MeetingOne);
 noisydarnClock.alarmRepeat(0,00,30,MeetingTwo);
 noisydarnClock.alarmRepeat(0,00,40,MeetingThree);
 noisydarnClock.alarmRepeat(0,00,59,MeetingFour);
 noisydarnClock.alarmRepeat(9,30,0,MeetingFive);
 noisydarnClock.alarmRepeat(10,00,0,MeetingSix);
 noisydarnClock.alarmRepeat(10,30,0,MeetingSeven);
 noisydarnClock.alarmRepeat(11,00,0,MeetingEight);
 noisydarnClock.alarmRepeat(15,00,0,MeetingNine);
 
}

GrooveFlotilla

#8
Apr 12, 2010, 12:34 pm Last Edit: Apr 12, 2010, 12:39 pm by GrooveFlotilla Reason: 1
What about :
Code: [Select]
#include <Time.h>
#include <TimeAlarms.h>
?

Or contact user "mem".
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1262783962/0
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

mem

#9
Apr 12, 2010, 01:17 pm Last Edit: Apr 12, 2010, 01:20 pm by mem Reason: 1
Quote
I assumed Alarm is an instance defined in TimeAlarms.h
A correct assumption, verified by this line in TimeAlarms.h
Code: [Select]
extern TimeAlarmsClass Alarm;  // make an instance for the user
The alarm library creates the Alarm object for the user (in the same way the serial library creates the Serial object), which is why there is no mention of objects in the documentation.

The Arduino convention of pre-creating objects that can only have a single instance can be surprising to experienced programmers at first, but as there always must be one and only one Alarm object in a sketch that uses this library, its a convenience for novices to have this ready to use.

BTW, there was an earlier version of the library that had a user created instance for each alarm but feedback indicated that the current version that has a single pre-created instance handling multiple alarms was easier for most Arduino users.


cne, the sketch you posted at the start of this thread compiles ok for me. Perhaps download and install the libraries again and see if it compiles for you.

The FAQ supplied with the library says that up to six alarms can be created but
after you have it compiling ok, you can change a define in TimeAlarms.h  to set the maximum number of alarms to 8
[font=Courier New]  #define dtNBR_ALARMS 8  // this is 6 in the distributed library
[/font]

cne

Code: [Select]
#include <Time.h>

#include <TimeAlarms.h>

const int ledPin =  13;      // the number of the LED pin
const int onPin = 5;

void setup()
{
 
 setTime(8,29,40,1,1,10); // set time to 8:29:40am Jan 1 2010

 Alarm.alarmRepeat(8,30,0,morningAlarm);  // 8:30am every day
 Alarm.alarmRepeat(8,30,10,otherAlarm);  
 
 pinMode(ledPin, OUTPUT);
 pinMode(onPin, OUTPUT);

}
void morningAlarm()
{
 digitalWrite(ledPin, HIGH);
 delay(500);
 digitalWrite(ledPin, LOW);
}

void otherAlarm()
{
 digitalWrite(ledPin, HIGH);
 delay(500);
 digitalWrite(ledPin, LOW);          
}

void  loop()
{  
 digitalWrite(onPin, HIGH);
}


I made a program to test out the alarm. The alarms should both go off in less than a miniute from start up, but they don't. Am I doing something wrong?

mem

#11
Apr 20, 2010, 03:51 am Last Edit: Apr 20, 2010, 03:53 am by mem Reason: 1
You need to call the Alarm.delay funtion from within loop.

The following is from the FAQ included in the readme file supplied with the library:

Task scheduling is handled in the Alarm.delay function.
Tasks are monitored and  triggered from within the Alarm.delay call so Alarm.delay should be called
whenever a delay is required in your sketch.
If your sketch waits on an external event (for example,  a sensor change),
make sure you repeatedly call Alarm.delay while checking the sensor.
You can call Alarm.delay(0) if you need to service the scheduler without a delay.


try  the following:
Code: [Select]
void  loop()
{  
 digitalWrite(onPin, HIGH);
 Alarm.delay(1);
}

cne

I have updated my main code, but when I turn it on, the alarm goes three times about 10s apart. When I turn pin 2 high, it sounds the alarm 6 times very fast. After this the program seems to stop.

Code: [Select]
//This program recieves a 1 second pulse at midnight for syncronization
//Alarms are referenced off that event
//The alarms sound a buzzer for one second on pin 13
//The circuit recieves a pulse on pin 2

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

const int midnightPin= 2;
const int timerPin= 13;
const int buzzerPin= 4;


int midnightState=0;

void setup()
{
 pinMode(midnightPin, INPUT);
 pinMode(timerPin, OUTPUT);
 pinMode(buzzerPin, OUTPUT);
 
 Alarm.alarmRepeat(0,00,10,MeetingOne);
 Alarm.alarmRepeat(0,00,20,MeetingTwo);
 Alarm.alarmRepeat(0,00,40,MeetingThree);
 Alarm.alarmRepeat(0,00,59,MeetingFour);
 Alarm.alarmRepeat(9,30,0,MeetingFive);
 Alarm.alarmRepeat(10,00,0,MeetingSix);
 Alarm.alarmRepeat(10,30,0,MeetingSeven);
 Alarm.alarmRepeat(11,00,0,MeetingEight);
 Alarm.alarmRepeat(15,00,0,MeetingNine);
 
}

void MeetingOne()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);  
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingTwo()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);  
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingThree()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);  
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingFour()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);  
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingFive()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);  
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingSix()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);  
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingSeven()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);  
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingEight()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);  
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingNine()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);  
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void  loop()
{
midnightState = digitalRead(midnightPin);  //reads the pulse
 if (midnightState == HIGH) {  
   setTime(23,59,0,1,1,10);  //sets time to one second before midnight
   Alarm.delay(0);
 }
 
}




mem

#13
Apr 21, 2010, 03:30 am Last Edit: Apr 21, 2010, 03:33 am by mem Reason: 1
why did you put the Alarm.delay call in the if statement?

alarms are only services when Alarm.Delay is called, but you only call this within the brief period of your midnight pulse.

Think of Alarm.delay as an enhanced version of the standard Arduino delay that while it is delaying also checks to see if an alarm has triggered.

cne

Code: [Select]
//This program recieves a 1 second pulse at midnight for syncronization
//Alarms are referenced off that event
//The alarms sound a buzzer for one second on pin 13
//The circuit recieves a pulse on pin 2

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

const int midnightPin= 2;
const int timerPin= 13;
const int buzzerPin= 4;


int midnightState=0;

void setup()
{
 pinMode(midnightPin, INPUT);
 pinMode(timerPin, OUTPUT);
 pinMode(buzzerPin, OUTPUT);

 Alarm.alarmRepeat(0,00,10,MeetingOne);
 Alarm.alarmRepeat(0,00,20,MeetingTwo);
 Alarm.alarmRepeat(0,00,40,MeetingThree);
 Alarm.alarmRepeat(0,00,59,MeetingFour);
 Alarm.alarmRepeat(9,30,0,MeetingFive);
 Alarm.alarmRepeat(10,00,0,MeetingSix);
 Alarm.alarmRepeat(10,30,0,MeetingSeven);
 Alarm.alarmRepeat(11,00,0,MeetingEight);
 Alarm.alarmRepeat(15,00,0,MeetingNine);

}

void MeetingOne()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingTwo()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingThree()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingFour()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingFive()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingSix()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingSeven()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingEight()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void MeetingNine()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);

}

void  loop()
{
midnightState = digitalRead(midnightPin);  //reads the pulse
 if (midnightState == HIGH) {
   setTime(23,59,0,1,1,10);  //sets time to one second before midnight
   
 }
Alarm.delay(0);
}







I updated the code, but it is still acting funny.

Go Up