Arduino Forum

Forum 2005-2010 (read only) => Software => Troubleshooting => Topic started by: cne on Mar 14, 2010, 06:55 pm

Title: Alarm
Post by: cne on Mar 14, 2010, 06:55 pm
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
Title: Re: Alarm
Post by: AWOL on Mar 14, 2010, 07:37 pm
I don't see an "Alarm" object.
Title: Re: Alarm
Post by: cne on Mar 14, 2010, 08:55 pm
Sorry, this could be a silly question,
But what is an alarm object?
Title: Re: Alarm
Post by: cne on Mar 17, 2010, 12:21 am
The code does contain this:

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

Title: Re: Alarm
Post by: PaulS on Mar 17, 2010, 10:56 am
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);
}
Title: Re: Alarm
Post by: mistergreen on Mar 24, 2010, 03:33 pm
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);
}


Title: Re: Alarm
Post by: mistergreen on Mar 24, 2010, 07:35 pm
make sure the Time library is in your libraries folder, perhaps.
Title: Re: Alarm
Post by: cne on Apr 12, 2010, 06:09 am
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);
 
}
Title: Re: Alarm
Post by: GrooveFlotilla on Apr 12, 2010, 12:34 pm
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
Title: Re: Alarm
Post by: mem on Apr 12, 2010, 01:17 pm
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]
Title: Re: Alarm
Post by: cne on Apr 20, 2010, 03:28 am
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?
Title: Re: Alarm
Post by: mem on Apr 20, 2010, 03:51 am
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);
}
Title: Re: Alarm
Post by: cne on Apr 21, 2010, 02:00 am
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);
 }
 
}



Title: Re: Alarm
Post by: mem on Apr 21, 2010, 03:30 am
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.
Title: Re: Alarm
Post by: cne on Apr 21, 2010, 04:19 am
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.
Title: Re: Alarm
Post by: mem on Apr 21, 2010, 04:33 am
Quote
but it is still acting funny.

Do you mean to say that it has exactly the same symptoms as before you made the change in loop?

If not, what are the symptoms?

edit: it would help you if you added some serial print statements in the alarm code to see which alarm was being triggered. You could also print the minute and second to show the time the alarm function was called.
Title: Re: Alarm
Post by: cne on Apr 21, 2010, 04:57 am
When I turn it on, it cycles through all of the alarms correctly, but after I turn pin 2 high, it sounds the alarm about 6 times really fast.
Title: Re: Alarm
Post by: mem on Apr 21, 2010, 05:26 am
The alarm logic does not expect time to run backwards and when you reset the clock back to the start of the previous day the scheduler can get confused.

If you want to adjust for drift, you could use the adjustTime function. This moves the clock forwards or backwards by a given number of seconds but does not disrupt the day and date.

Here is an untested fragment of code you could use when you get your sync pulse. To try this you should run it in real time-  the drift calculation will not be realistic if you feed it sync pulses much more frequently than every 24 hours.

Code: [Select]
 
 long  drift = elapsedSecsToday(now());
 // if the elapsed time since previous midnight is a big number,
 // then its not quite reached midnight so the clock is slow
 // as small positive number means it running fast
 if(drift > 3600)  
   drift = drift - SECS_PER_DAY ;   // clock slow - this will be a negative number
 // a positive number indicates that the clock has passed midnight so its fast
 Serial.print("the drift in seconds is ");
 Serial.println(drift);
 adjustTime(-drift); // compensate by adding  seconds if slow, subtract if fast  


BTW, where are your sync pulses coming from?
Title: Re: Alarm
Post by: cne on Apr 21, 2010, 05:42 am
I used your suggestion on the serial.
The program works great, except for the fact that when the midnight pulse is recieved, the program cyles through all the alarms quickly. Is there a way to prevent this?
Also, when the power is turned on, the time is set to 0:00:00 automaticly. Is there a way to prevent this?

Here is the serial monitor:
Code: [Select]


Power Up:
0:00:00
0:00:01
0:00:02
0:00:03
..........


MIDNIGHT PULSE RECIEVED
MEETING ONE CALLED
MEETING TWO CALLED
MEETING THREE CALLED
MEETING FOUR CALLED
MEETING FIVE CALLED
MEETING SIX CALLED
1:00:05
1:00:06
1:00:07
.........

Title: Re: Alarm
Post by: cne on Apr 21, 2010, 05:48 am
I am building a meeting alarm that will be tied in with an existing clock system. All the clocks are syncronised at midnight via 1 second DC pulse. Using this reference point I can make sure all the meetings are correctly timed compared to the clocks.
Title: Re: Alarm
Post by: mem on Apr 21, 2010, 06:19 am
Quote
when the midnight pulse is recieved, the program cyles through all the alarms quickly.


Did you try the suggestions in my previous post.
also:
Quote
To try this you should run it in real time-  the drift calculation will not be realistic if you feed it sync pulses much more frequently than every 24 hours.


Quote
when the power is turned on, the time is set to 0:00:00 automaticly. Is there a way to prevent this?

You can set the time in setup before you set the alarms
Title: Re: Alarm
Post by: mem on Apr 21, 2010, 06:30 am
If only six of the nine alarms are triggering, read through the earlier posts in this thread that explained how to increase the number of alarms.
Title: Re: Alarm
Post by: cne on Apr 23, 2010, 05:22 am
I used your suggestion. It works to set the time to 0:00:00, but the alarms do not trigger after the midnight reset. I also changed the number of alarms.

Here is the serial report...
Code: [Select]
0:00:00
0:00:01
0:00:02
0:00:03
0:00:04
0:00:05
0:00:06
0:00:07
0:00:08
0:00:09
MEETING CALL
MEETING ONE CALLED
0:00:11
0:00:12
0:00:13
0:00:14
0:00:15
0:00:16
0:00:17
0:00:18
0:00:19
MEETING CALL
MEETING TWO CALLED
0:00:21
0:00:22
0:00:23
0:00:24
0:00:25
0:00:26
0:00:27
0:00:28
0:00:29
MEETING CALL
MEETING THREE CALLED
0:00:31
0:00:32
0:00:33
0:00:34
0:00:35
0:00:36
0:00:37
0:00:38
0:00:39
MEETING CALL
MEETING FOUR CALLED
0:00:41
0:00:42
0:00:43
0:00:44
0:00:45
0:00:46
0:00:47
0:00:48
0:00:49
MEETING CALL
MEETING FIVE CALLED
0:00:51
0:00:52
0:00:53
0:00:54
0:00:55
0:00:56
0:00:57
0:00:58
MEETING CALL
MEETING SIX CALLED
0:01:00
0:01:01
0:01:02
0:01:03
0:01:04
0:01:05
0:01:06
0:01:07
0:01:08
0:01:09
MEETING CALL
MEETING SEVEN CALLED
0:01:11
0:01:12
0:01:13
0:01:14
0:01:15
0:01:16
0:01:17
0:01:18
0:01:19
MEETING CALL
MEETING EIGHT CALLED
0:01:21
0:01:22
0:01:23
0:01:24
0:01:25
0:01:26
0:01:27
0:01:28
0:01:29
MEETING CALL
MEETING NINE CALLED
0:01:31
0:01:32
0:01:33
0:01:34
0:01:35
0:01:36
0:01:37
0:01:38
0:01:39
the drift in seconds is 100
MIDNIGHT PULSE RECIEVED
0:00:00
0:00:01
0:00:02
0:00:03
0:00:04
0:00:05
0:00:06
0:00:07
0:00:08
0:00:09
0:00:10 //Meeting One is suppoused to go off here
0:00:11
0:00:12
0:00:13
0:00:14
0:00:15
0:00:16
0:00:17
Title: Re: Alarm
Post by: mem on Apr 23, 2010, 11:35 am
Lets have a look, can you post the sketch
Title: Re: Alarm
Post by: cne on Apr 23, 2010, 05:35 pm
Here it is...


Code: [Select]
#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,30,MeetingThree);
 Alarm.alarmRepeat(0,00,40,MeetingFour);
 Alarm.alarmRepeat(0,00,50,MeetingFive);
 Alarm.alarmRepeat(0,00,59,MeetingSix);
 Alarm.alarmRepeat(0,01,10,MeetingSeven);
 Alarm.alarmRepeat(0,01,20,MeetingEight);
 Alarm.alarmRepeat(0,01,30,MeetingNine);
 
 Serial.begin(9600);    
 
}

void MeetingOne()
{
 MeetingCall();
 Serial.println("MEETING ONE CALLED");    
}

void MeetingTwo()
{
 MeetingCall();
 Serial.println("MEETING TWO CALLED");
}

void MeetingThree()
{
 MeetingCall();
 Serial.println("MEETING THREE CALLED");
}

void MeetingFour()
{
 MeetingCall();
 Serial.println("MEETING FOUR CALLED");  
}

void MeetingFive()
{
 MeetingCall();
 Serial.println("MEETING FIVE CALLED");
}

void MeetingSix()
{
 MeetingCall();
 Serial.println("MEETING SIX CALLED");  
}

void MeetingSeven()
{
 MeetingCall();
 Serial.println("MEETING SEVEN CALLED");
}


void MeetingEight()
{
 MeetingCall();
 Serial.println("MEETING EIGHT CALLED");
}

void MeetingNine()
{
 MeetingCall();
 Serial.println("MEETING NINE CALLED");
}

void MeetingCall()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);  
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);
 Serial.println("MEETING CALL");
}

void  loop()
{
midnightState = digitalRead(midnightPin);  //reads the pulse
 if (midnightState == HIGH) {  
   long  drift = elapsedSecsToday(now());
 // if the elapsed time since previous midnight is a big number,
 // then its not quite reached midnight so the clock is slow
 // as small positive number means it running fast
 if(drift > 3600)  
   drift = drift - SECS_PER_DAY ;   // clock slow - this will be a negative number
 // a positive number indicates that the clock has passed midnight so its fast
 Serial.print("the drift in seconds is ");
 Serial.println(drift);
 adjustTime(-drift); // compensate by adding  seconds if slow, subtract if fast  

   Serial.println("MIDNIGHT PULSE RECIEVED");
   
 }
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);
}
Title: Re: Alarm
Post by: mem on Apr 23, 2010, 05:52 pm
The code looks ok.

Try it with the alarms  set to a few minutes after midnight. Your drft is almost two minutes but the alarms are supposed to go off within a minute.

I wonder why you have so much drift. For a timekeeping application a board with a crystal would be more suitable because the drift would only be couple of seconds per day. What board are you using?
Title: Re: Alarm
Post by: cne on Apr 23, 2010, 11:15 pm
I am using the Duemilanove.
Isn't the drift just how many seconds have passed since midnight?
0:00:00
.......
0:01:40 //Midnight Pulse

=100 seconds
Title: Re: Alarm
Post by: mem on Apr 24, 2010, 12:16 pm
Quote
Isn't the drift just how many seconds have passed since midnight?

Yes, but standard arduino board should not drift more than 2 or 3 seconds per day.

what board are you using?
Title: Re: Alarm
Post by: cne on Apr 24, 2010, 06:05 pm
I am using the Duemilanove