Pages: [1] 2 3   Go Down
Author Topic: clock with multiple alarms  (Read 4776 times)
0 Members and 1 Guest are viewing this topic.
Indonesia
Offline Offline
Newbie
*
Karma: 1
Posts: 49
ayooo,,,DAB!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First, i am noob in arduino and just tinkering arduino.

i want to make a clock using :

1. Arduino UNO
2. RTC DS1307
3. LCD 16*2 character

and using this library :

#include <Time.h>
#include <TimeAlarms.h>
#include <Wire.h> 
#include <DS1307RTC.h>
#include <EEPROM.h>
#include <LiquidCrystal.h>

the purpose of my sketch :
1. Read Serial data VB from VB to set RTC if Serial Header is 'T'          => achieved
   example : T1310258400 set RTC to July 10th 2011. 00:40:00
2. Read Serial data VB from VB to write EEPROM if Serial Header is 'I'
   example :
      I180018050001180318080001
      * then save :
      *  //room 1
      *  - 18 to EEPROM address 200 ==> alarm start hour       //room 1
      *  - 00 to EEPROM address 201 ==> alarm start minute   //room 1
      *  - 18 to EEPROM address 202 ==> alarm stop hour      //room 1
      *  - 05 to EEPROM address 203 ==> alarm stop minute      //room 1
      *  - 00 to EEPROM address 204 ==> alarm interval hour   //room 1
      *  - 01 to EEPROM address 205 ==> alarm interval minute   //room 1
      *  //room 2
      *  - 18 to EEPROM address 206 ==> alarm start hour       //room 2
      *  - 03 to EEPROM address 207 ==> alarm start minute   //room 2
      *  - 18 to EEPROM address 208 ==> alarm stop hour      //room 2
      *  - 08 to EEPROM address 209 ==> alarm stop minute      //room 2
      *  - 00 to EEPROM address 210 ==> alarm interval hour   //room 2
      *  - 01 to EEPROM address 211 ==> alarm interval minute   //room 2
      * desired output:
      * alarm in room 1 ring every 1 minutes since 18.00 up to 18.05
      * alarm in room 2 ring every 1 minutes since 18.03 up to 18.08

I have asked my problems on this thread:
http://arduino.cc/forum/index.php/topic,66054.msg484148.html#msg484148
my progress is on that thread, as summary, my sketch only handle 1 room alarm

and my next step is design 2 alarm for 2 room that can have different "start, stop, and interval" alarm value.
the example application is clock in industry,
clock for staff (from 08.00 up to 14.00 = room 1), clock for machine operator (8 hour shift/day = room 2)

So, i figure out the code will be the same as mem's fragment before (http://arduino.cc/forum/index.php/topic,66054.msg485651.html#msg485651), but something wrong when I run it.

and this is part of my sketch:

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

AlarmID_t alarm1;
AlarmID_t alarm2;

void setup()
{
  Serial.begin(9600);
  lcd.begin(16,2);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  setSyncInterval(600);
  lcd.clear();
  //room 1
  Alarm.alarmRepeat(18,00,00, Start1);  //start room 1
  Alarm.alarmRepeat(18,05,30, Stop1);  // End room 1
  alarm1 = Alarm.timerRepeat( 1 * SECS_PER_MIN, doRING1);
  //room 2
  Alarm.alarmRepeat(18,03,30, Start2);  //start room 2
  Alarm.alarmRepeat(18,08,30, EndIntSlave2);  // End room 2
  alarm2 = Alarm.timerRepeat( 1 * SECS_PER_MIN, doRING2); 
}
void Start1()
{
  Alarm.enable(alarm1); //room 1 start alarm
}

void Stop1()
{
  Alarm.disable(alarm1);//room 1 stop alarm
}

void doRING1()
{
  lcd.print("1111111111111111");//room 1 interval
}
void Start2()
{
  Alarm.enable(alarm2);//room 2 start alarm
}

void Stop2()
{
  Alarm.disable(alarm2);//room 2 stop alarm
}

void doRING2()
{
  lcd.print("2222222222222222");//room 2 interval
}

...
loop, etc

and here's the output :
   18.00.00 : room 1, start the alarm       = as desired
   18.00.50 : alarm 2 is ringing          ======>>>> undesired output
   18.01.00 : alarm 1 is ringing          = as desired
   18.01.50 : alarm 2 is ringing          ======>>>> undesired output
   18.02.00 : alarm 1 is ringing          = as desired
   18.02.50 : alarm 2 is ringing          ======>>>> undesired output
   . . .
   18.03.30 : room 2, start the alarm       = as desired
   18.04.30 : alarm 2 is ringing          = as desired
   18.05.30 : room 1, stop the alarm       = as desired
   . . .
   10.08.30 : room 2, stop the alarm       = as desired


Quote
smiley-kitty thanks, and sorry for my english smiley-kitty
regards,
.cop.
« Last Edit: July 22, 2011, 05:25:54 am by copet_pitik » Logged

Program Studi Instrumentasi Medis
Politeknik Mekatronika Sanata Dharma
Yogyakarta Indonesia

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you need to disable the timers until the alarm has triggered. Change the setup code as follows:

Code:
  //room 1
  Alarm.alarmRepeat(18,00,00, Start1);  //start room 1
  Alarm.alarmRepeat(18,05,30, Stop1);  // End room 1
  alarm1 = Alarm.timerRepeat( 1 * SECS_PER_MIN, doRING1);
  Alarm.disable(alarm1); // <-this timer will be enabled when the alarm triggers
  //room 2
  Alarm.alarmRepeat(18,03,30, Start2);  //start room 2
  Alarm.alarmRepeat(18,08,30, EndIntSlave2);  // End room 2
  alarm2 = Alarm.timerRepeat( 1 * SECS_PER_MIN, doRING2); 
  Alarm.disable(alarm2); // <- this timer will be enabled when the alarm triggers

everything else looks ok but I have not tried it so let me know if that fixes it
Logged

Indonesia
Offline Offline
Newbie
*
Karma: 1
Posts: 49
ayooo,,,DAB!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, previous problem solved.
your code works, mem. thanks again.

another problems,
if have place the code (Alarm.alarmRepeat...etc) on setup,
so when i send the alarm time from VB and save it to EEPROM, then I have to reset the arduino, right?
what should I do if I don't want to reset the arduino?

thanks for any suggestions or helps

.cop.
Logged

Program Studi Instrumentasi Medis
Politeknik Mekatronika Sanata Dharma
Yogyakarta Indonesia

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't need to reset the Arduino, you can simply write the new alarm time to the alarm

You will need to add alarm IDs for all of the alarms you want to change - here is an example of how to do this:

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

// variables holding the IDs for alarms and timers that can be set from VB
AlarmID_t alarm1Start, alarm1Stop, alarm1Timer; 
AlarmID_t alarm2tart, alarm2top, alarm2Timer;

void setup()
{
  Serial.begin(9600);
  lcd.begin(16,2);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  setSyncInterval(600);
  lcd.clear();

 //room 1
  alarm1Start = Alarm.alarmRepeat(18,00,00, Start1);  //start room 1
  alarm1Stop = Alarm.alarmRepeat(18,05,30, Stop1);  // End room 1
  alarm1Timer = Alarm.timerRepeat( 1 * SECS_PER_MIN, doRING1);
  Alarm.disable(alarm1Timer); // <-this timer will be enabled when the alarm triggers

  //room 2
  alarm2Start = Alarm.alarmRepeat(18,03,30, Start2);  //start room 2
  alarm2Start = Alarm.alarmRepeat(18,08,30, EndIntSlave2);  // End room 2
  alarm2Timer = Alarm.timerRepeat( 1 * SECS_PER_MIN, doRING2); 
  Alarm.disable( alarm2Timer); // <- this timer will be enabled when the alarm triggers 
}

void Start1()
{
  Alarm.enable(alarm1Timer); //room 1 start alarm
}

void Stop1()
{
  Alarm.disable(alarm1Timer);//room 1 stop alarm
}

void doRING1()
{
  lcd.print("1111111111111111");//room 1 interval
}
void Start2()
{
  Alarm.enable(alarm2Timer);//room 2 start alarm
}

void Stop2()
{
  Alarm.disable(alarm2Timer);//room 2 stop alarm
}

void doRING2()
{
  lcd.print("2222222222222222");//room 2 interval
}

You change the alarm time by calling alarm.write with the alarm id you want to change and the new alarm value.
here is some pseudocode:

   time_t newTime =  AlarmHMS(17, 30,00); // variable newTime contains the time value for 17:30:00
   Alarm.write(alarm1Start,newTime); // change the alarm1 start time to the given newTime
Logged

Indonesia
Offline Offline
Newbie
*
Karma: 1
Posts: 49
ayooo,,,DAB!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

my code is not working, must be something wrong with it.

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

AlarmID_t alarm1Start, alarm1Stop, alarm1Timer; 
AlarmID_t alarm2Start, alarm2Stop, alarm2Timer;

void setup()
{
  Serial.begin(9600);
  lcd.begin(16,2);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  setSyncInterval(600);
  lcd.clear();

 //room 1
  alarm1Start = Alarm.alarmRepeat(18,00,00, Start1);  //start room 1
  alarm1Stop  = Alarm.alarmRepeat(18,05,30, Stop1);  // End room 1
  alarm1Timer = Alarm.timerRepeat( 1 * SECS_PER_MIN, doRING1);
  Alarm.disable(alarm1Timer); // <-this timer will be enabled when the alarm triggers

  //room 2
  alarm2Start = Alarm.alarmRepeat(18,03,30, Start2);  //start room 2
  alarm2Stop  = Alarm.alarmRepeat(18,08,30, EndIntSlave2);  // End room 2
  alarm2Timer = Alarm.timerRepeat( 1 * SECS_PER_MIN, doRING2); 
  Alarm.disable( alarm2Timer); // <- this timer will be enabled when the alarm triggers 
}

void loop()
{
  Alarm.delay(0);
  if(Serial.available())
  {
    char header = Serial.read();
    if (header == TIME_HEADER) //serial data to set the RTC
      processSyncMessage();
    else if (header == INT_SLAVE) //serial data to set the alarm
      changeValue(); //if serial available, change The Alarm Value
    else if (header == OTHERS)
      BlinkBlink();
  }
  digitalClockDisplay();
  delay(1000);
}

void changeValue()
{
...//EEPROM.write address 200 - 211
...
...
char c = EEPROM.read (200); //hourEEPROM    ==>1//START HOUR
char d = EEPROM.read (201); //minuteEEPROM  ==>1//START MINUTE
char e = EEPROM.read (202); //hourEEPROM    ==>1//STOP HOUR
  char f = EEPROM.read (203); //minuteEEPROM  ==>1//STOP MINUTE
  char g = EEPROM.read (204); //hourEEPROM    ==>1//INTERVAL HOUR
  char h = EEPROM.read (205); //minuteEEPROM  ==>1//INTERVAL MINUTE
  char i = EEPROM.read (206); //hourEEPROM          ==>2//START HOUR
  char j = EEPROM.read (207); //minuteEEPROM        ==>2//START MINUTE
  char k = EEPROM.read (208); //hourEEPROM          ==>2//STOP HOUR
  char l = EEPROM.read (209); //minuteEEPROM        ==>2//STOP MINUTE
  char m = EEPROM.read (210); //hourEEPROM          ==>2//INTERVAL HOUR
  char n = EEPROM.read (211); //minuteEEPROM        ==>2//INTERVAL MINUTE
 
  //================================================================room 1
  time_t newStart1 = AlarmHMS (c, d, 0);
  Alarm.write (alarm1Start, newStart1); // change START alarm value ROOM 1
  time_t newEnd1   = AlarmHMS (e, f, 30);
  Alarm.write (alarm1End, newEnd1); // change STOP alarm value ROOM 1
  time_t newInterval1 = AlarmHMS (g, h, 0);
  Alarm.write (alarm1Timer, newInterval1) ; // change TIMER value ROOM 1
  //================================================================room 2
  time_t newStart2 = AlarmHMS (i, j, 10);
  Alarm.write (alarm2Start, newStart2); // change START alarm value ROOM 2
  time_t newEnd2   = AlarmHMS (k, l, 30);
  Alarm.write (alarm2End, newEnd2); // change STOP alarm value ROOM 2
  time_t newInterval2 = AlarmHMS (m, n, 0);
  Alarm.write (alarm2Timer, newInterval2) ; // change TIMER value ROOM 2
}

It is right, mem?
I'm sorry, I am totally noob for this stuff. smiley-cry smiley-cry smiley-cry
Logged

Program Studi Instrumentasi Medis
Politeknik Mekatronika Sanata Dharma
Yogyakarta Indonesia

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you will find things will go easier of you take one step at a time.

As I suggested in the other thread, don't worry about eeprom until after you have everything else working.

The next step is to ensure that you are handling the serial messages correctly.  If you print the values of variables c through n, to the serial port, are they correct?
if not, you need to fix your serial input routines. If they hour minutes and interval are being received correctly then you need to say exactly what it is that is not working correctly.

Logged

Indonesia
Offline Offline
Newbie
*
Karma: 1
Posts: 49
ayooo,,,DAB!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The next step is to ensure that you are handling the serial messages correctly.  If you print the values of variables c through n, to the serial port, are they correct?
if not, you need to fix your serial input routines. If they hour minutes and interval are being received correctly then you need to say exactly what it is that is not working correctly.
this code (below)on void setup() is working,
room 1 alarm's rings every minute since 18:00:00 until 18:05:30
room 2 alarm's rings every minute since 18:03:30 until 18:08:30

Code:
  //room 1
  Alarm.alarmRepeat(18,0,00, Start1);  //start room 1
  Alarm.alarmRepeat(18,5,30, Stop1);  // End room 1
  alarm1 = Alarm.timerRepeat( 1 * SECS_PER_MIN, doRING1);
  Alarm.disable(alarm1); // <-this timer will be enabled when the alarm triggers
  //room 2
  Alarm.alarmRepeat(18,3,30, Start2);  //start room 2
  Alarm.alarmRepeat(18,8,30, EndIntSlave2);  // End room 2
  alarm2 = Alarm.timerRepeat( 1 * SECS_PER_MIN, doRING2); 
  Alarm.disable(alarm2); // <- this timer will be enabled when the alarm triggers

So, my next step is trying to combine your code in post #3 with my EEPROM sketch, but it is not working.
the undesired output are:
when I send serial data from VB at 18:03:15 (RTC time), both alarm will ring at 18:04:15 and won't stop.

the value c through n is correct when i print to serial.
this is the code that I used:
Code:
  Serial.println (i, DEC);
  Serial.println (j, DEC);
  Serial.println (k, DEC);
  Serial.println (l, DEC);

I'll make and try another sketches to change the value of the alarm.
Logged

Program Studi Instrumentasi Medis
Politeknik Mekatronika Sanata Dharma
Yogyakarta Indonesia

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you post the sketch that prints values from the serial requests and sets the alarms that has all the eeprom code removed I will see I can help. Please say what data you are sending and how the sketch is misbehaving.
Logged

Indonesia
Offline Offline
Newbie
*
Karma: 1
Posts: 49
ayooo,,,DAB!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley-sad-blue smiley-sad-blue smiley-sad-blue
it is not working again.
I've removed my eeprom code and still got undesired output.
this is my my sketch (this sketch using RTC library):
Code:
#include <Time.h>
#include <TimeAlarms.h>
#include <Wire.h> 
#include <DS1307RTC.h>

//Serial data parsing RTC Function
#define TIME_MSG_LEN  11   
#define TIME_HEADER  'T'   
//===========end============
//Serial data parsing for ALARM
#define PJG_DATA 25
#define INT_SLAVE 'I'
//===========end============

//==Serial Variable for ROOM 1==
byte hourStart1 = 0;
byte minuteStart1 = 0;
byte hourStop1 = 0;
byte minuteStop1 = 0;
byte hourInterval1 = 0;
byte minuteInterval1 = 0;
//==Serial Variable for ROOM 2==
byte hourStart2 = 0;
byte minuteStart2 = 0;
byte hourStop2 = 0;
byte minuteStop2 = 0;
byte hourInterval2 = 0;
byte minuteInterval2 = 0;
//===========end===========

//==================ALARM ID==================
AlarmID_t alarmStart1, alarmStop1, alarmTimer1; //ID for interval Slave 1
AlarmID_t alarmStart2, alarmStop2, alarmTimer2; //ID for interval Slave 2
//====================end=====================

void setup()
{
  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  setSyncInterval(600);
  if(timeStatus()!= timeSet)
    Serial.println("Can't sync RTC! ");
  else
    Serial.println(" Can sync RTC!  ");
  delay(1000);
  //ROOM 1
  alarmStart1 = Alarm.alarmRepeat(22, 40, 00, Start1); //==start alarm mode interval slave 1
  alarmStop1   = Alarm.alarmRepeat(22, 42, 30, Stop1); //==stop alarm mode interval slave 1
  alarmTimer1 =  Alarm.timerRepeat( 1 * SECS_PER_MIN, doRing1 );
  Alarm.disable(alarmTimer1);
  //ROOM 2
  alarmStart2 = Alarm.alarmRepeat(22, 41, 10, Start2); //==start alarm mode interval slave 2
  alarmStop2   = Alarm.alarmRepeat(22, 43, 30, Stop2); //==stop alarm mode interval slave 2
  alarmTimer2 =  Alarm.timerRepeat( 2 * SECS_PER_MIN, doRing2 );
  Alarm.disable(alarmTimer2);
}

void  loop(){
  if(Serial.available())
  {
    char header = Serial.read();
    if (header == TIME_HEADER)
      processSyncMessage();
    else if (header == INT_SLAVE)
      Interval();
  }
  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)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

//========================reading UNIX TIME==========================//
void processSyncMessage()
{
  time_t pctime = 0;
  while (Serial.available() > TIME_MSG_LEN);
  for(int i=0; i < TIME_MSG_LEN -1; i++)
  {   
    char c = Serial.read();
    if( c >= '0' && c <= '9'){   
      pctime = (10 * pctime) + (c - '0') ; 
    }
  }
  time_t t = pctime;
  RTC.set(t);
  setTime(t);
}
//=========CHANGE ALARM data from SERIAL MESSAGE =========//
void Interval()
{
  char setString[PJG_DATA];
  int index = 0;
  for (int i = 0; i < PJG_DATA - 1; i++)
  {
    char d = Serial.read();
    setString[index++] = d - '0';
  }
  int count = index;
  int element = 0;
  for( index = 0; index < count; index += 2)
  {
    byte val = setString[index] * 10 + setString[index+1];
    switch (element++){
      //===========for ROOM 1===========
    case 0:
      hourStart1 = val;
      break;
    case 1:
      minuteStart1 = val;
      break;
    case 2:
      hourStop1 = val;
      break;
    case 3:
      minuteStop1 = val;
      break;
    case 4:
      hourInterval1 = val;
      break;
    case 5:
      minuteInterval1 = val;
      break;
      //===========for ROOM 2===========
    case 6:
      hourStart2 = val;
      break;
    case 7:
      minuteStart2 = val;
      break;
    case 8:
      hourStop2 = val;
      break;
    case 9:
      minuteStop2 = val;
      break;
    case 10:
      hourInterval2 = val;
      break;
    case 11:
      minuteInterval2 = val;
      break;
    }
  }
  //================================================================room 1
  time_t newStart1 = AlarmHMS (hourStart1, minuteStart1, 0);
  Alarm.write (alarmStart1, newStart1);
  time_t newStop1   = AlarmHMS (hourStop1, minuteStop1, 30);
  Alarm.write (alarmStop1, newStop1);
  time_t newInterval1 = AlarmHMS (hourInterval1, minuteInterval1, 0);
  Alarm.write (alarmTimer1, newInterval1) ;
  //================================================================room 2
  time_t newStart2 = AlarmHMS (hourStart2, minuteStart2, 10);
  Alarm.write (alarmStart2, newStart2);
  time_t newStop2   = AlarmHMS (hourStop2, minuteStop2, 30);
  Alarm.write (alarmStop2, newStop2);
  time_t newInterval2 = AlarmHMS (hourInterval2, minuteInterval2, 0);
  Alarm.write (alarmTimer2, newInterval2) ;
  //check alarm data ROOM 1
  Serial.println(hourStart1, DEC);
  Serial.println(minuteStart1, DEC);
  Serial.println(hourStop1, DEC);
  Serial.println(minuteStop1, DEC);
  Serial.println(hourInterval1, DEC);
  Serial.println(minuteInterval1, DEC);
  //check alarm data ROOM 2
  Serial.println(hourStart2, DEC);
  Serial.println(minuteStart2, DEC);
  Serial.println(hourStop2, DEC);
  Serial.println(minuteStop2, DEC);
  Serial.println(hourInterval2, DEC);
  Serial.println(minuteInterval2, DEC);
}
/*==================== ALARM ROOM 1, START and STOP =================*/
//==================================================================================
void Start1(){
  Alarm.enable(alarmTimer1);
  Serial.println("ROOM 1111111 START");
  delay(1000);
}
void Stop1(){
  Alarm.disable(alarmTimer1);
  Serial.println("ROOM 1111111 STOP");
  delay(1000);
}

void doRing1(){
  Serial.println("^^^^^^one^^^^^^");
  delay(1000);
}
/*==================== ALARM ROOM 2, START and STOP =================*/
//==================================================================================
void Start2(){
  Alarm.enable(alarmTimer2);
  Serial.println("ROOM 2222222 START");
  delay(1000);
}
void Stop2(){
  Alarm.disable(alarmTimer2);
  Serial.println("ROOM 2222222 STOP");
  delay(1000);
}

void doRing2(){
  Serial.print("2222~t w o~2222 ");
  delay(1000);
}


Quote
what data you are sending?

I send this data : I225122530001225222540002
ROOM 1 : start alarm at : 22:51, stop the alarm at : 22:53, and alarm's interval : 1 minute
ROOM 2 : start alarm at : 22:52, stop the alarm at : 22:54, and alarm's interval : 2 minute

this is the output of serial data parsing:
Code:
Can sync RTC!
22:50:51
22:50:52
22
51
22
53
0
1
22
52
22
54
0
2
22:50:53
22:50:54
22:50:55
22:50:56

Quote
how the sketch is misbehaving?

the alarm is not working or show that alarm for room 1/2 is start/stop.
and alarm's timer is start counting (and never ends) since received the data ( I225122530001225222540002, arduino received data on 20:20:53)

this is the misbehaving output from Serial Monitor:
Code:
...
22:51:51
22:51:52
^^^^^^one^^^^^^
22:51:54
22:51:55
...
...
22:52:51
22:52:52
^^^^^^one^^^^^^
2222~t w o~2222 22:52:55
22:52:56
22:52:57
...
...
22:53:51
22:53:52
^^^^^^one^^^^^^22:53:54
22:53:55
22:53:56
...
...
22:54:51
22:54:52
^^^^^^one^^^^^^
2222~t w o~2222 22:54:55
22:54:56
22:54:57
...
...
22:55:51
22:55:52
^^^^^^one^^^^^^22:55:54
22:55:55
22:55:56
...
...
22:56:51
22:56:52
^^^^^^one^^^^^^
2222~t w o~222222:56:55
22:56:56
22:56:57
...
...
...
...
from this output I make a conclusion that the alarm start counting when arduino received serial data (input).
thanks for any helps.

.cop.
Logged

Program Studi Instrumentasi Medis
Politeknik Mekatronika Sanata Dharma
Yogyakarta Indonesia

Upstate NY
Offline Offline
Full Member
***
Karma: 2
Posts: 184
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Incorrect question asked.
« Last Edit: July 24, 2011, 12:45:26 pm by JoeO » Logged

Indonesia
Offline Offline
Newbie
*
Karma: 1
Posts: 49
ayooo,,,DAB!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

JoeO,
nothings wrong when I compiled that sketch,
maybe that is the alternate syntax in arduino, but I'm not sure..hehehe smiley-draw..
thanks JoeO..
Logged

Program Studi Instrumentasi Medis
Politeknik Mekatronika Sanata Dharma
Yogyakarta Indonesia

Upstate NY
Offline Offline
Full Member
***
Karma: 2
Posts: 184
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry - you are using a correct form of IfElse.
« Last Edit: July 24, 2011, 12:39:04 pm by JoeO » Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are reading the serial port without first checking to ensure that all 24 characters have been received.

I modified your Interval() function to do the the check and have simplified the implementation by converting the received digits into integer values on the fly instead of stroring the characters in an array.

I have not tested this and you may need to tweak this but I hope this gets you going in the right direction.
 
Code:
// returns the integer value of the given number of ascii digits
int getIntFromAscii(int nbrDigits)
{
  int val = 0;
  for(int i=0; i < nbrDigits; i++) {
    val = (val *10) + Serial.read()- '0';
  }
  return  val;
}

//=========CHANGE ALARM data from SERIAL MESSAGE =========//
void Interval()
{
  unsigned long startTime = millis();
  while(Serial.available() < 24)
  {
    if(millis() - startTime > 1000)
    {
       Serial.println("got header but timed out waiting for 24 bytes");
       return;
    }
  }   

   //===========for ROOM 1===========
   hourStart1 = getIntFromAscii(2);
   minuteStart1 = getIntFromAscii(2);
   hourStop1 = getIntFromAscii(2);
   minuteStop1 =getIntFromAscii(2);
   hourInterval1 = getIntFromAscii(2);
   minuteInterval1 =getIntFromAscii(2);
   //===========for ROOM 2===========
   hourStart2 = getIntFromAscii(2);
   minuteStart2 = getIntFromAscii(2);
   hourStop2 = getIntFromAscii(2);
   minuteStop2 = getIntFromAscii(2);
   hourInterval2 = getIntFromAscii(2);
   minuteInterval2 = getIntFromAscii(2)

  //================================================================room 1
 the code to set the alarms and print the values goes here...
Logged

Indonesia
Offline Offline
Newbie
*
Karma: 1
Posts: 49
ayooo,,,DAB!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mem, still not getting any this time..
the optimized code is working,
but alarm can not start or stop at the time as I set.
the serial output is same as my earlier post.

still tinkering and tweaking more.. smiley-roll smiley-roll smiley-roll

-----------------------------------------------------------------------------------------
2nd try:
I check the alarm ID 0 up to 5, the result is the alarms have been set as what I send in serial input
data that I send : I185118530001185218540002

Code:

18:50:46
 repeat alarm with ID 0 set for 18:51:00
 repeat alarm with ID 1 set for 18:53:30
 repeat alarm with ID 2 set for 0:01:00
 repeat alarm with ID 3 set for 18:52:10
 repeat alarm with ID 4 set for 18:54:30
 repeat alarm with ID 5 set for 0:02:00
18:50:47
18:50:48
...
...

and I am still get the alarm ring every 1 and 2 minutes.
this is the serial monitor output:
Code:
18:51:46
^^^^^^one^^^^^^
18:51:48
...
...
18:52:46
2222~t w o~2222 18:52:48
^^^^^^one^^^^^^
18:52:49
...
...
...

« Last Edit: July 25, 2011, 07:04:24 am by copet_pitik » Logged

Program Studi Instrumentasi Medis
Politeknik Mekatronika Sanata Dharma
Yogyakarta Indonesia

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am not clear on what is not working, how are you checking to make sure that the time you are setting are correct?

If you change the setup values to the times you are sending in your message, does the sketch work as expected?
Logged

Pages: [1] 2 3   Go Up
Jump to: