Arduino Time Alarm Question

Hallo

I have Question about the Time Alarm Librarie.

The Question:

How i can change Alarm.timerRepeat look like my code below:

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

void setup()
{
  Serial.begin(9600);
  
}

void  loop(){
  
  char comRead = Serial.read();
  
  if (comRead == 65) {
    int pcHour = Serial.parseInt();
    int pcMins = Serial.parseInt();
    int pcSeconds = Serial.parseInt();
    int StartHour = Serial.parseInt();
    int StartMins = Serial.parseInt();
    
    setTime(pcHour,pcMins,pcSeconds,2,3,15);
    Alarm.timerRepeat(StartHour,StartMins,0, TestOne);
  }
  
  if (comRead == 66) {
    int pcHour = Serial.parseInt();
    int pcMins = Serial.parseInt();
    int pcSeconds = Serial.parseInt();
    int StopHour = Serial.parseInt();
    int StopMins = Serial.parseInt();
    
    setTime(pcHour,pcMins,pcSeconds,2,3,15);
    Alarm.timerRepeat(StopHour,StopMins,0, TestTwo);
  }
  digitalClockDisplay();
  Alarm.delay(1000); // wait one second between clock display
}

void TestOne() {
  
  Serial.println("TESTONE");
  
}

void TestTwo() {
  Serial.println("TESTTWO");
}

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);
}

The problem is when i send the Stop Time the timer not working... It is posible to make that ? The idea is to make easily change the Alarm's

The problem is when i send the Stop Time the timer not working

How do you "send the Stop Time"?

The Alarm.timerRepeat() method creates a NEW timer. That is unlikely to be what you want to do when you want to change the time of an existing timer.

PaulS:
How do you "send the Stop Time"?

The Alarm.timerRepeat() method creates a NEW timer. That is unlikely to be what you want to do when you want to change the time of an existing timer.

Sorry i write wrong code for that. On my code i send hours from serial port look like this 12,12,0,12,13 Turn On and turn off look like 12,12,0,12,14

The first three numbers is for setTime and second two numbers is for Turn On (12,13) And Turn Off (12,14)

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

void setup()
{
  Serial.begin(9600);
  
}

void  loop(){
  
  char comRead = Serial.read();
  
  if (comRead == 65) {
    int pcHour = Serial.parseInt();
    int pcMins = Serial.parseInt();
    int pcSeconds = Serial.parseInt();
    int StartHour = Serial.parseInt();
    int StartMins = Serial.parseInt();
    
    pcHour = constrain(pcHour, 0 ,24);
    pcMins = constrain(pcMins, 0, 59);
    pcSeconds = constrain(pcSeconds, 0, 59);
    StartHour = constrain(StartHour, 0, 24);
    StartMins = constrain(StartMins, 0 , 59);
    
    setTime(pcHour,pcMins,pcSeconds,2,3,15);
    Alarm.alarmRepeat(StartHour,StartMins,0, TestOne);
  }
  
  if (comRead == 66) {
    int pcHour = Serial.parseInt();
    int pcMins = Serial.parseInt();
    int pcSeconds = Serial.parseInt();
    int StopHour = Serial.parseInt();
    int StopMins = Serial.parseInt();
    
    pcHour = constrain(pcHour, 0 ,24);
    pcMins = constrain(pcMins, 0, 59);
    pcSeconds = constrain(pcSeconds, 0, 59);
    StopHour = constrain(StopHour, 0, 24);
    StopMins = constrain(StopMins, 0 , 59);
    
    setTime(pcHour,pcMins,pcSeconds,2,3,15);
    Alarm.alarmRepeat(StopHour,StopMins,0, TestTwo);
  }
  digitalClockDisplay();
  Alarm.delay(1000); // wait one second between clock display
}

void TestOne() {
  
  Serial.println("TESTONE");
  
}

void TestTwo() {
  Serial.println("TESTTWO");
}

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);
}

And the problem now is work only two times and when i send again the new hours stop working....

Try my code and look what's hapening

On my code i send hours from serial port look like this 12,12,0,12,13 Turn On and turn off look like 12,12,0,12,14

Then what the heck is this:

  char comRead = Serial.read();
  if (comRead == 65) {

..sir, is there any way that i can put a variable in the timeAlarm function in setting particular alarm? especially in setting (DayOfWeek)/ days of the week..?

is there any way that i can put a variable in the timeAlarm function in setting particular alarm?

This question, as stated, makes no sense. There is a TimeAlarm CLASS. (Yes, case matters). There is not a timeAlarms FUNCTION.

You can call any method in the TimeAlarm class with a variable instead of a constant. The C language is a pass-by-value language, so using a variable or a value will result in the function getting exactly the same data, and not knowing whether the caller used a variable or a value (or caring).

sorry i'm just a newbie.. i'm making a project title interactive digital clock.,once you call time, it will responce the current time.. same as the date, temperature and the alarm.. my problem is, in setting the alarm. i want to set a value particularly on the hourStart1 and minuteStart1..

time_t newStart1 = AlarmHMS (hourStart1, minuteStart1, 0);
Alarm1 = Alarm.alarmRepeat(newStart1, alarmTone);

crixus_markus:
sorry i'm just a newbie.. i'm making a project title interactive digital clock.,once you call time, it will responce the current time.. same as the date, temperature and the alarm.. my problem is, in setting the alarm. i want to set a value particularly on the hourStart1 and minuteStart1..

time_t newStart1 = AlarmHMS (hourStart1, minuteStart1, 0);
Alarm1 = Alarm.alarmRepeat(newStart1, alarmTone);

Well, as a snippet, that looks like it might be at least on the path to working. It's hard to tell without seeing all the code, as AlarmHMS() is probably your function. So what is your problem?

aarg:
Well, as a snippet, that looks like it might be at least on the path to working. It's hard to tell without seeing all the code, as AlarmHMS() is probably your function. So what is your problem?

sir aarg.. i want set a value on hourStart1 and minuteStart1..thourgh a for loop function..
i can show you my codes..

crixus_markus:
sir aarg.. i want set a value on hourStart1 and minuteStart1..thourgh a for loop function..
i can show you my codes..

You can show everyone your codes. Please use code tags, as explained in the forum sticky posts at the top.

That is a shitload of improperly posted code to illustrate a simple problem. Read the damned stickies and post your code PROPERLY.

Post a SIMPLE program to illustrate the problem you are having.

i want set a value on hourStart1 and minuteStart1..thourgh a for loop function..

You have our permission.

Next time I'm using the boilerplate reply to questions without code. It's more specific.

int const h1 = 1 || 1;

What the heck? Explain!

..sir the 1 is the value of the pos through for loop.. the other 1 is the value i put..so that if i press the triggerYes on h1 it will have the value 1. sir i really wont know if it's correct..to have a value.. apologies...

..sir the 1 is the value of the pos through for loop.. the other 1 is the value i put..so that if i press the triggerYes on h1 it will have the value 1.

Nonsense. You can't just make up syntax. The || operator has a well defined purpose. You can't reuse it that way and expect reasonable behavior.

You need to completely re-think what you are doing and how to accomplish it WITHOUT inventing syntax.

Why do you need any h variables ?
Loop through the values 1 to 24 (or do you mean 0 to 23) and display the values. When the selection button becomes pressed stop the loop and save the value..

UKHeliBob:
Why do you need any h variables ?
Loop through the values 1 to 24 (or do you mean 0 to 23) and display the values. When the selection button becomes pressed stop the loop and save the value..

sir UKheliBob i put h variable to declare for the for-loop function..
hourStart1 = pos; to have the value hour in AlarmHMS();

time_t newStart1 = AlarmHMS(hourStart1, minuteStart1);
alarm1 = Alarm.alarmRepeat(newStart1, alarmTone);

sir apologies, i really don't know if it's correct.. any advice sir?

PaulS:
Nonsense. You can't just make up syntax. The || operator has a well defined purpose. You can't reuse it that way and expect reasonable behavior.

You need to completely re-think what you are doing and how to accomplish it WITHOUT inventing syntax.

apologies sir PaulS..i'm just a newbie, any method sir you know to set a value on hourStart1 and minuteStart1?

crixus_markus:
sir UKheliBob i put h variable to declare for the for-loop function..
hourStart1 = pos; to have the value hour in AlarmHMS();

time_t newStart1 = AlarmHMS(hourStart1, minuteStart1);
alarm1 = Alarm.alarmRepeat(newStart1, alarmTone);

sir apologies, i really don't know if it's correct.. any advice sir?

I had in mind something like this

for loop 0 to 23
  display current number
  read input button
  if button becomes depressed within a short time
    save the current number to a new variable
    exit for loop
  end if
end for loop
use the saved number

any method sir you know to set a value on hourStart1 and minuteStart1?

hourStart1 = lateInTheDay();
minuteStart1 = 89;