Program flow


Out of setup() and loop()

  • Comments: Program name, version, creator, hardware list.
  • #include statements, including parameterset4clock1.h, which contains the values for display brightness, volume etc., which can be set individually for each alarm clock you build in a separate file (parameterset4clock2.h, ...clock3.h etc.).
  • Declaration (and partial definition) of objects, constants, variables, functions.

 

In setup()

  • Assignment of the digital input and output pins.
  • To avoid noise that may be transmitted from the displays to the speaker: Disconnect the speaker from the output of the MP3 module via relay contact.
  • Initialize displays, read display potentiometer values and adjust brightness.
  • Initialize MP3 player, read volume potentiometer, adjust volume.
  • Initialize FRAM module, read hour and minute values, check and transfer to the variables.
  • Switch on the colon of the time display.
  • To avoid missing the alarm in the event of a mains power failure after restarting the Arduino and to sound the alarm reliably in this case as well: check whether the hours and minutes of time and alarm time are identical. If so: Play the alarm MP3 file.

 

In loop()

  • Read display potentiometer values and adjust the brightness
  • Read in volume potentiometer value and adjust the volume
  • Read hours, minutes and seconds from the clock module (RTC) and write them into the variables

  • Check whether the clock rotary switch is set to "Set"
    • If not
      • Switch off flashing of the display
    • If so:
      • Check whether one of the setting buttons is held down
        • If not
          • Switch on display flashing
        • If so
          • Switch off flashing of the display
          • Increase or decrease the hour or minute value of the corresponding variable according to the key pressed and write it to the RTC.
          • Write the seconds of the clock(!) time to the alarm display
  • Write hours and minutes to the clock display
  • Check whether the alarm rotary switch is set to "On" or "Set"
  • If the alarm switch is set to "On" AND the clock switch is NOT set to "Set":
    • Switch off alarm display flashing, display colon, display alarm time
    • If the FRAM module does not contain the current alarm time values (because you have just switched from "Set alarm" to "Alarm on")
      • Rewrite FRAM, set variables and notice that FRAM is now up to date again
  • If the alarm switch is set to "Set" AND the clock switch is NOT set to "Set":
    • Show colon
    • Check whether one of the setting buttons is held down
      • If not
        • Switch on display flashing
      • If so
        • Switch off flashing of the display
        • Increase or decrease the hour or minute value of the corresponding variable according to the key pressed and notice that the FRAM is no longer up to date.
  • Write hours and minutes to the alarm display

  • If the alarm rotary switch is neither set to "On" nor to "Set" and the clock rotary switch is also not set to "Set"
    • Clear the alarm display

  •  Check if the MP3 file is NOT currently playing
    • If so
      • Open relay contact to the speaker

  • Check whether the alarm switch is set to "On" AND the time (hour, minute and second) matches the alarm time AND the MP3 file is not already running
    • If so
      • Close relay contact, start playback of MP3 file
    • Check whether the alarm switch is NOT set to "On"
      • If so
        • Check if the MP3 file is currently playing
          • If so
            • Stop playback, open relay contact