Go Down

Topic: Setting Alarm Problem (Read 2009 times) previous topic - next topic

cellage

Jan 22, 2011, 07:59 pm Last Edit: Jan 22, 2011, 09:52 pm by cellage Reason: 1
I want to set an alarm with a specified serially read time I've tried every thing i can ,I even created a new function inside the library but nothing get me there
I need Help

Code: [Select]
void loop() {
 
digitalClockDisplay();
Alarm.delay(1000);
   if (Serial.available()>0)
{  
 
 char setString[TIME_SET_StrLen];
 int index = 0;
char c = Serial.read();
if( c != '[')
    return;  // first character must be opening square brackets
 do
 {
    c = Serial.read();
    if( isdigit(c))  // non numeric characters are discarded
      setString[index++] = c -'0'; // convert from ascii    
 }
 while (c != ']'); // wait for trailing square brackets

int count = index;
 int element = 0;
 for( index = 0; index < count; index += 2)  // step through each pair of digits
 {
     int val = setString[index] * 10 + setString[index+1] ; // get the numeric value of the next pair of numbers
switch( element++){
       case  0 :  Hour = val; break;
       case  1 :  Minute = val; break;
       case  2 :  Second = val; break;
}  
} }  
 
Serial.print(Hour );
 Serial.print(Minute);
  Serial.print(Second);
  Serial.println("go to school");
 
    Alarm.alarmRepeat(20,20,0, MorningAlarm);
     Alarm.alarmRepea(Hour,Minute,Second,EveningAlarm); // my new function it works fine but not with serial date
 
 }


the function on the library
Code: [Select]

AlarmID_t TimeAlarmsClass::alarmRepea(int H, int M, int S, OnTick_t onTickHandler){
    return create( AlarmHMS(H,M,S), onTickHandler, IS_ALARM, IS_REPEAT );
}

PaulS

Quote
but nothing get me there

What does the code you posted actually do? How does that differ from what you actually want it to do?

Give us a clue where the problem is/

cellage

i want to enter the values of hours,minutes,seconds from a serial interface (vb) and set the alarm on the value received , but the function
Alarm.alarmRepeat(Hour,Minute,Second,EveningAlarm);

doesnt work unless it had a constant time value specified from within the  arduino [glow]and again i need to send the value from a vb[/glow]

so I was wondering if there is a way to set the alarm in another way

note: I use
#include <Time.h>  
#include <TimeAlarms.h>

AWOL

My phone browser doesn't show all your code but it looks like you're reading characters that may not be there.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

Serial data transmission is sssslllloooowwww, The Arduino is fast, by comparison. You should declare the array to hold the serial data as a global variable, and populate it in a while loop, until there is no more serial data or until the end-of-packet marker is received.

cellage

I thought in a  different way without referencing to the alarm library and used a simple if-statement

Code: [Select]
  if (hour()== Hour &&  minute() == Minute)
  {

    EveningAlarm1();
  }
 

This is what i want , thanks for help and suggestions  :D

Go Up