PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

94 Zeilen
2.5KB

  1. /*
  2. * TimeAlarmExample.pde
  3. *
  4. * This example calls alarm functions at 8:30 am and at 5:45 pm (17:45)
  5. * and simulates turning lights on at night and off in the morning
  6. * A weekly timer is set for Saturdays at 8:30:30
  7. *
  8. * A timer is called every 15 seconds
  9. * Another timer is called once only after 10 seconds
  10. *
  11. * At startup the time is set to Jan 1 2011 8:29 am
  12. */
  13. // Questions? Ask them here:
  14. // http://forum.arduino.cc/index.php?topic=66054.0
  15. #include <TimeLib.h>
  16. #include <TimeAlarms.h>
  17. AlarmId id;
  18. void setup() {
  19. Serial.begin(9600);
  20. while (!Serial) ; // wait for Arduino Serial Monitor
  21. setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011
  22. // create the alarms, to trigger at specific times
  23. Alarm.alarmRepeat(8,30,0, MorningAlarm); // 8:30am every day
  24. Alarm.alarmRepeat(17,45,0,EveningAlarm); // 5:45pm every day
  25. Alarm.alarmRepeat(dowSaturday,8,30,30,WeeklyAlarm); // 8:30:30 every Saturday
  26. // create timers, to trigger relative to when they're created
  27. Alarm.timerRepeat(15, Repeats); // timer for every 15 seconds
  28. id = Alarm.timerRepeat(2, Repeats2); // timer for every 2 seconds
  29. Alarm.timerOnce(10, OnceOnly); // called once after 10 seconds
  30. }
  31. void loop() {
  32. digitalClockDisplay();
  33. Alarm.delay(1000); // wait one second between clock display
  34. }
  35. // functions to be called when an alarm triggers:
  36. void MorningAlarm() {
  37. Serial.println("Alarm: - turn lights off");
  38. }
  39. void EveningAlarm() {
  40. Serial.println("Alarm: - turn lights on");
  41. }
  42. void WeeklyAlarm() {
  43. Serial.println("Alarm: - its Monday Morning");
  44. }
  45. void ExplicitAlarm() {
  46. Serial.println("Alarm: - this triggers only at the given date and time");
  47. }
  48. void Repeats() {
  49. Serial.println("15 second timer");
  50. }
  51. void Repeats2() {
  52. Serial.println("2 second timer");
  53. }
  54. void OnceOnly() {
  55. Serial.println("This timer only triggers once, stop the 2 second timer");
  56. // use Alarm.free() to disable a timer and recycle its memory.
  57. Alarm.free(id);
  58. // optional, but safest to "forget" the ID after memory recycled
  59. id = dtINVALID_ALARM_ID;
  60. // you can also use Alarm.disable() to turn the timer off, but keep
  61. // it in memory, to turn back on later with Alarm.enable().
  62. }
  63. void digitalClockDisplay() {
  64. // digital clock display of the time
  65. Serial.print(hour());
  66. printDigits(minute());
  67. printDigits(second());
  68. Serial.println();
  69. }
  70. void printDigits(int digits) {
  71. Serial.print(":");
  72. if (digits < 10)
  73. Serial.print('0');
  74. Serial.print(digits);
  75. }