Created
May 13, 2018 21:47
-
-
Save 7effrey89/123fc8d60e4d8758f80065758cd95eb9 to your computer and use it in GitHub Desktop.
WIP - alarm nodemcu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 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 weekly timer is set for Saturdays at 8:30:30 | |
| * | |
| * 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 2011 8:29 am | |
| */ | |
| // Questions? Ask them here: | |
| // http://forum.arduino.cc/index.php?topic=66054.0 | |
| #include <TimeLib.h> | |
| #include <TimeAlarms.h> | |
| #define maxAlarms 6 //7 Alarms | |
| AlarmId id; | |
| void setup() { | |
| Serial.begin(115200); | |
| while (!Serial) ; // wait for Arduino Serial Monitor | |
| //Define array of alarms | |
| int myAlarms[maxAlarms]; | |
| myAlarms[0] = | |
| //Alarm Format | |
| //WeekOfDay: Monday 1, Tuesday 2, Wednesday 3, Thursday 4, Friday 5, Sataurday 6, Sunday 7; | |
| //Hour: between 01-23; | |
| //Min: between 01-59; | |
| //Alarm Frequency: Once 1, Daily 2, Weekly 3; | |
| //Alarm State: On 1, Off 0; | |
| setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011 | |
| // create the alarms, to trigger at specific times | |
| 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 | |
| id = Alarm.timerRepeat(2, Repeats2); // timer for every 2 seconds | |
| Alarm.timerOnce(10, OnceOnly); // called once after 10 seconds | |
| } | |
| void loop() { | |
| digitalClockDisplay(); | |
| Alarm.delay(1000); // wait one second between clock display | |
| Serial.println("jeffrey"); | |
| } | |
| // 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); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment