it exceeds the 900 chaector length I will try and just include the upper half... I apologize I am new to this
#include <DS3232RTC.h>
/**
- Description:
- This is an example sketch that builds an Alarm Clock out of an Arduino Uno,
- an LCD Keypad Shield, a DS1307 Real Time Clock, and a buzzer
- The example lets you display the date and time, and also set the alarm.
- There are 4 modes of operation in which the buttons on the LCD have specific functions.
- "Display Date Time" mode: Date, Time, and an Alarm indication display on the LCD (default mode)
- SELECT: Lets you set the alarm time
- LEFT: Displays the current alarm time
- RIGHT: Turns the alarm on and off
- "Display Alarm Time":
- No active buttons. After 3 seconds the clock returns to the default mode
- "Set Alarm" mode: Lets you set the alarm time (hours & minutes)
- UP: Increases hours/minutes **
- DOWN: Decreases hours/minutes **
- SELECT: Accepts the hours/minutes value
- "Buzzer Ringing" mode: When the alarm time has been met, the buzzer rings
- SELECT or LEFT: Turns off the buzzer and the alarm
- UP or DOWN: Snooze -> Adds 10 minutes to the alarm time
- ** After 5 seconds of inactivity, the clock returns to default mode
- Note 1:
- The development of the code was based on a Finite State Machine (FSM)
- you can find on github: GitHub - nlamprian/AlarmClock: Arduino sketch that makes use of an LCD Keypad Shield and a DS1307 RTC to build an alarm clock
- The code is quite simple and was made possible due to the above
- preliminary design. You are urged to study both the FSM and the code.
- Note 2:
- The time on the RTC can shift over time. If you notice a deviation building up,
- just uncomment line 91 and load the example to your Arduino. That will set the
- computer's time on the RTC. Afterwards, make sure to reupload the code with
- line 91 commented out. If you don't do that, the next time your Arduino resets
- it will write the time again on the RTC... the time of the code's compilation.
- Author:
- Nick Lamprianidis { paign10.ln [at] gmail [dot] com }
- License:
- Copyright (c) 2014 Nick Lamprianidis
- This code is released under the MIT license
-
The MIT License – Open Source Initiative
*/
#include <Wire.h> // Required by RTClib
#include <LiquidCrystal.h> // Required by LCDKeypad
#include <LCDKeypad.h>
#include <DS3232RTC.h>"
#define TIME_OUT 5 // One of the system's FSM transitions
#define ALARM_TIME_MET 6 // One of the system's FSM transitions
#define BUZZER_PIN 3 // Output PWM pin for the buzzer
#define SNOOZE 10 // Minutes to snooze
// The different states of the system
enum states
{
SHOW_TIME, // Displays the time and date
SHOW_TIME_ALARM_ON, // Displays the time and date, and alarm is on
SHOW_ALARM_TIME, // Displays the alarm time and goes back to time and date after 3 seconds
SET_ALARM_HOUR, // Option for setting the alarm hours. If provided, it moves on to alarm minutes.
// Otherwise, it times out after 5 seconds and returns to time and date
SET_ALARM_MINUTES, // Option for setting the alarm minutes. If provided, it finally sets the alarm time and alarm.
// Otherwise, it times out after 5 seconds and returns to time and date
BUZZER_ON // Displays the time and date, and buzzer is on (alarm time met)
};
// Creates an LCDKeypad instance
// It handles the LCD screen and buttons on the shield
LCDKeypad lcd;
// Creates an RTC_DS1307 instance
// It handles the DS1307 Real-Time Clock
DS3232RTC rtc;
states state; // Holds the current state of the system
int8_t button; // Holds the current button pressed
uint8_t alarmHours = 0, alarmMinutes = 0; // Holds the current alarm time
uint8_t tmpHours;
boolean alarm = false; // Holds the current state of the alarm
unsigned long timeRef;
DateTime now ; // Holds the current date and time information