Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HELP to Use more than one Alarm ID #58

Open
joko2020 opened this issue Jul 30, 2021 · 0 comments
Open

HELP to Use more than one Alarm ID #58

joko2020 opened this issue Jul 30, 2021 · 0 comments

Comments

@joko2020
Copy link

Description

More than one Alarm ID , but all of ID are triggered even once of the ID has disable condition

Steps To Reproduce Problem

Hardware & Software

Board ESP32 Dev Board
Shields / modules Not used
Arduino IDE version 1.8.12
Teensyduino version (if using Teensy)
Version info & package name (from Tools > Boards > Board Manager) ESP 32 Dev Module
Operating system & version Windows 7 64 Profesional
Any other software or hardware?

Arduino Sketch

`// Questions? Ask them here:
// http://forum.arduino.cc/index.php?topic=66054.0

#include <TimeLib.h>
#include <TimeAlarms.h>

AlarmId id1;
AlarmId id2;

void setup() {
Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor

setTime(8,00,0,7,30,21); // set time to Saturday 8:29:00am Jan 1 2011

// create the alarms, to trigger at specific times
id2= Alarm.alarmRepeat(8,30,0, MorningAlarm); // 8:30am every day
// Alarm.alarmRepeat(17,45,0,EveningAlarm); // 5:45pm every day
// Alarm.alarmRepeat(dowSaturday,8,30,30,WeeklyAlarm); // 8:30:30 every Saturday

// create timers, to trigger relative to when they're created
Alarm.timerRepeat(15, Repeats); // timer for every 15 seconds
id1 = Alarm.timerRepeat(2, Repeats2); // timer for every 2 seconds
Alarm.timerOnce(10, OnceOnly); // called once after 10 seconds

AlarmId.disable(id1);
AlarmId.enable(id2);

}

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

// functions to be called when an alarm triggers:
void MorningAlarm() {
Serial.println("Alarm: - turn lights off");
}

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

void WeeklyAlarm() {
Serial.println("Alarm: - its Monday Morning");
}

void ExplicitAlarm() {
Serial.println("Alarm: - this triggers only at the given date and time");
}

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

void Repeats2() {
Serial.println("2 second timer");
}

void OnceOnly() {
Serial.println("This timer only triggers once, stop the 2 second timer");
// use Alarm.free() to disable a timer and recycle its memory.
Alarm.free(id);
// optional, but safest to "forget" the ID after memory recycled
id = dtINVALID_ALARM_ID;
// you can also use Alarm.disable() to turn the timer off, but keep
// it in memory, to turn back on later with Alarm.enable().
}

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

Result Both AlarmId are Triggered

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant