130 likes | 521 Views
Alarm Clock. Robert Stuart. Functions of an Alarm Clock. Keep track of time. When the time matches a stored value an alarm should go off. Functionality that allows for the user to set the time to a desired value. Functionality that allows for the user to set the alarm to a desired value.
E N D
Alarm Clock Robert Stuart
Functions of an Alarm Clock Keep track of time. When the time matches a stored value an alarm should go off. Functionality that allows for the user to set the time to a desired value. Functionality that allows for the user to set the alarm to a desired value. Allow for the alarm function to be enabled or disabled. Incorporate a snooze feature Display the time and the alarm time.
Implementation Hours, Minutes, Seconds variables introduced by Phil. Needed to add in some code to have the hours operate in the 12-hr system and to keep track of am and pm. A simple test to see if the time and the stored alarm time are the same. 3/4. Use one on board button to switch between 3 modes: Running, Settime, and Setalarm. To be able to set the time or the alarm I used another 3 on board buttons; one to toggle between the hours and the minutes being selected, and the other two to increase or decrease the selected variable. 5. To ensure this function is not changed by accident, it requires two of the on board buttons to be pressed and released simultaneously. 6. An additional large button that when pressed disables the alarm for five minutes (from when the snooze button was pressed, not when the alarm first went off). 7. An LCD display allows for more information to be displayed in an easy to understand format. I have included the time (or alarm time), a decimal point to indicate the state of the alarm, another decimal point to show pm, and a letter to indicate what mode you are in.
Code – Start and Running Loop Set up input/output ports Declare and initialize all variables Running loop if change mode pressed goto Set Time loop if enable/disable alarm pressed switch the state of that variable if alarm is enabled goto tests for the alarm Goto Running
Set Time Loop Set Time Loop if up button pressed increase current variable (either Hours or Minutes) if down button pressed decrease current variable (either Hours or Minutes) if Hr/Min button pressed toggle between the variables Hours and Minutes if enable/disable button pressed toggle enabled/disabled if mode button pressed goto Set Alarm loop Goto Set Time loop
Set Alarm Loop Set Alarm Loop if up button pressed increase current variable (either AHR or AMI) if down button pressed decrease current variable (either AHR or AMI) if Hr/Min button pressed toggle between the variables AHR and AMI if enable/disable button pressed toggle enabled/disabled if mode button pressed goto Running loop Goto Set Alarm loop
Tests for Alarm Test AM/PM if AM/PM matches for alarm and time goto test hours Return Test hours if Hours and AHR are the same gototest minutes Return Test minutes if Minutes and AMI are the same gototest seconds Return Test seconds if Seconds is 0 goto Alarming Loop! Return
Alarming Loop! Alarming Loop if Snooze button has been pressed increase alarming variable by 5 minutes and goto Tests for Alarm if Snooze button hasn’t been pressed BEEP! if off button pressed turn alarm off and go back to Running if enable/disable button pressed turn alarm off, disable alarm function, and go back to Running Goto Alarming Loop