Overview

This project features an alarm clock that can only be disabled by pressing a button located across the room from the users sleeping location.

Device Overview

User interface consisting of an I2C LCD display, 2 potentiometers, and a push button.

User turning off alarm using the deactivation button.

Process Images and Review

As a mechanical engineer, I have developed a fascination with the working world around me. I like to see how things work and how they differ from other objects and products similar to them. This prompted me to construct  my final iteration using clear acrylic to house the electronic components of my alarm clock.

I originally intended to use an LED light strip mounted above the users bed as another method of notifying the user to wake up. I decided against this due to the extra power required and increase in the wiring needed to be installed in order to have the lights mounted externally.

Clear acrylic allows user to see the inner workings of the clock and also makes it easier to see the LED when alarm is triggered.

LED mounted inside the device decreases the amount of external wiring required and also illuminates and emphasizes the electrical components of it.

  • Clear acrylic allows user to see the inner workings of the clock and also makes it easier to see LED when alarm is triggered.

    Discussion

    I received a lot of valuable feedback during the in-class critique. One of the responses recommended the following: “It would be cool if a bluetooth module was added to connect the two parts instead of string.” This idea crossed my mind as well. I ultimately decided not to include a bluetooth. In an attempt to make the device more power efficient, I decided against using methods involving extra power and/or a constant need for power. This is also the reason I decided against using an LED strip and including a continuously running clock. Other feedback that I received stated “maybe add a different power source which would make it more long term.” I could not agree with this more. The end goal of the project was to include a power supply that could be plugged into a wall outlet. I chose to keep the battery as a power source to ensure easy setup and portability during  the building and revision process as well as the peer feedback portion of the project.

  • Overall I am satisfied with the result of my project. It does everything that I intended for it to do while remaining in line with my goal of reducing overall power needs for the gadget. Although I met my main goals for the project, I found that reducing power led to my project having less of a wow-factor to it.  Along with this sort of interesting vs. efficient balance that exists, this project also helped me come to notice some of the patterns that I have developed in terms of my own work flow. It took me some time to figure out how to use the I2C LCD screen that I implemented in my device. I spent countless hours trying to figure this out when I could have spent that time working on other aspects of my project. It has helped me realize the importance of utilizing the resources that are available to me as early and often as possible so that I do not waste as much time working on something that can be accomplished much faster with a little bit of help. This is definitely something I would do if I had the chance to do it all over again. I do not see myself iterating again on this project, but if I were to, I would most likely make the device invoke more of a sense of urgency. By this I mean more lights and more noise. After being placed in the enclosure, the noise became a little quieter than I had intended, and this is definitely something that can be easily fixed.
  • Technical Information

  • Wiring Schematic

 

  • Code 
    1. <span class="com">/*Wake Me Wake Alarm
    2. Justin Belardi
    3. Funtionality:
    4. The following code uses readings from 2 potentiometers to set values for hours and minutes.
    5. Upon the press of the set button, the software sets a timer based on the values from the
    6. potentiometers. When the timer reaches zero, an LED flashes and a buzzer beeps, prompting
    7. the user to wake up. The alarm continues sounding and flahing light until the user presses
    8. the stop button located across the room.
    9. Pin Mapping:
    10. Hour Changer: Pin A0
    11. Minute Changer: Pin A1
    12. Set Time Button: Pin 2
    13. Diasrm Button: Pin 3
    14. LED: Pin 6
    15. Buzzer: Pin 9
    16. Credits:
    17. Intro to Physical Computing Code Byte - Displaying data on an I²C LCD screen
    18. -Used for learning how to implement the I2C LCD Screen.
    19. -Setup Code for initializing Screen was used in final software for project
    20. */</span><span class="pln">
    21. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><Wire.h></span><span class="pln">
    22. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><LiquidCrystal_I2C.h></span><span class="pln">
    23. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> HRPOT </span><span class="pun">=</span><span class="pln"> A0</span><span class="pun">;</span><span class="pln">
    24. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> MINPOT </span><span class="pun">=</span><span class="pln"> A1</span><span class="pun">;</span><span class="pln">
    25. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> SETBUT </span><span class="pun">=</span><span class="pln"> </span><span class="lit">2</span><span class="pun">;</span><span class="pln">
    26. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> STOPBUT </span><span class="pun">=</span><span class="pln"> </span><span class="lit">3</span><span class="pun">;</span><span class="pln">
    27. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> LED </span><span class="pun">=</span><span class="pln"> </span><span class="lit">6</span><span class="pun">;</span><span class="pln">
    28. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> buzzer </span><span class="pun">=</span><span class="pln"> </span><span class="lit">9</span><span class="pun">;</span><span class="pln">
    29. </span><span class="com">//Initilize variables used to set timer and countdown</span><span class="pln">
    30. </span><span class="kwd">int</span><span class="pln"> hrRead </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    31. </span><span class="kwd">int</span><span class="pln"> minRead </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    32. </span><span class="kwd">int</span><span class="pln"> hours </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    33. </span><span class="kwd">int</span><span class="pln"> mins </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    34. </span><span class="kwd">int</span><span class="pln"> timer </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    35. </span><span class="kwd">int</span><span class="pln"> hrsLeft </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    36. </span><span class="kwd">int</span><span class="pln"> minLeft </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    37. </span><span class="kwd">int</span><span class="pln"> secLeft </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    38. </span><span class="com">//Initializing state variables that are used to tell the software which </span><span class="pln">
    39. </span><span class="com">//loop that should be run based on previous code and user input.</span><span class="pln">
    40. </span><span class="kwd">volatile</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> setState </span><span class="pun">=</span><span class="pln"> LOW</span><span class="pun">;</span><span class="pln">
    41. </span><span class="kwd">volatile</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> stopAlarm </span><span class="pun">=</span><span class="pln"> LOW</span><span class="pun">;</span><span class="pln">
    42. </span><span class="typ">LiquidCrystal_I2C</span><span class="pln"> screen</span><span class="pun">(</span><span class="lit">0x27</span><span class="pun">,</span><span class="pln"> </span><span class="lit">16</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">);</span><span class="pln">
    43. </span><span class="kwd">void</span><span class="pln"> setup</span><span class="pun">(){</span><span class="pln">
    44. pinMode</span><span class="pun">(</span><span class="pln">HRPOT</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
    45. pinMode</span><span class="pun">(</span><span class="pln">MINPOT</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
    46. pinMode</span><span class="pun">(</span><span class="pln">SETBUT</span><span class="pun">,</span><span class="pln"> INPUT_PULLUP</span><span class="pun">);</span><span class="pln">
    47. attachInterrupt</span><span class="pun">(</span><span class="pln">digitalPinToInterrupt</span><span class="pun">(</span><span class="pln">SETBUT</span><span class="pun">),</span><span class="pln"> start</span><span class="pun">,</span><span class="pln"> RISING</span><span class="pun">);</span><span class="pln">
    48. pinMode</span><span class="pun">(</span><span class="pln">STOPBUT</span><span class="pun">,</span><span class="pln"> INPUT_PULLUP</span><span class="pun">);</span><span class="pln">
    49. attachInterrupt</span><span class="pun">(</span><span class="pln">digitalPinToInterrupt</span><span class="pun">(</span><span class="pln">STOPBUT</span><span class="pun">),</span><span class="pln"> alarmOff</span><span class="pun">,</span><span class="pln"> RISING</span><span class="pun">);</span><span class="pln">
    50. pinMode</span><span class="pun">(</span><span class="pln">LED</span><span class="pun">,</span><span class="pln">OUTPUT</span><span class="pun">);</span><span class="pln">
    51. </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">(</span><span class="lit">9600</span><span class="pun">);</span><span class="pln">
    52. screen</span><span class="pun">.</span><span class="pln">init</span><span class="pun">();</span><span class="pln">
    53. screen</span><span class="pun">.</span><span class="pln">backlight</span><span class="pun">();</span><span class="pln">
    54. screen</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">
    55. </span><span class="pun">}</span><span class="pln">
    56. </span><span class="kwd">void</span><span class="pln"> loop</span><span class="pun">(){</span><span class="pln">
    57. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">setState </span><span class="pun">==</span><span class="pln"> LOW</span><span class="pun">){</span><span class="pln"> </span><span class="com">//If the set button has not been pressed yet...</span><span class="pln">
    58. screen</span><span class="pun">.</span><span class="pln">home</span><span class="pun">();</span><span class="pln">
    59. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">" Set Sleep Time "</span><span class="pun">);</span><span class="pln">
    60. stopAlarm </span><span class="pun">=</span><span class="pln"> LOW</span><span class="pun">;</span><span class="pln">
    61. hrRead </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">HRPOT</span><span class="pun">);</span><span class="pln">
    62. minRead </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">MINPOT</span><span class="pun">);</span><span class="pln">
    63. hours </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">hrRead</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">1023</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">24</span><span class="pun">);</span><span class="pln">
    64. mins </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">minRead</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">1023</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">60</span><span class="pun">);</span><span class="pln">
    65. screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">);</span><span class="pln">
    66. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">((</span><span class="typ">String</span><span class="pun">)</span><span class="pln"> </span><span class="str">"Hrs: "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> hours </span><span class="pun">+</span><span class="pln"> </span><span class="str">" Min: "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> mins </span><span class="pun">+</span><span class="str">" "</span><span class="pun">);</span><span class="pln">
    67. timer </span><span class="pun">=</span><span class="pln"> hours</span><span class="pun">*</span><span class="lit">3600</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> mins</span><span class="pun">;</span><span class="pln">
    68. </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">((</span><span class="typ">String</span><span class="pun">)</span><span class="pln"> </span><span class="str">"Hours: "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> hours </span><span class="pun">+</span><span class="pln"> </span><span class="str">" Minutes: "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> mins</span><span class="pun">);</span><span class="pln">
    69. </span><span class="pun">}</span><span class="pln">
    70. </span><span class="kwd">else</span><span class="pun">{</span><span class="pln">
    71. </span><span class="com">//simulates a timer by looping until a value of zero is reahed</span><span class="pln">
    72. </span><span class="com">//while reducing time value by 1 and delaying 1000 ms (1 second)</span><span class="pln">
    73. </span><span class="kwd">while</span><span class="pln"> </span><span class="pun">(</span><span class="pln">timer </span><span class="pun">></span><span class="pln"> </span><span class="lit">0</span><span class="pun">){</span><span class="pln">
    74. timer </span><span class="pun">=</span><span class="pln"> timer </span><span class="pun">-</span><span class="pln"> </span><span class="lit">1</span><span class="pun">;</span><span class="pln">
    75. </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">timer</span><span class="pun">);</span><span class="pln">
    76. delay</span><span class="pun">(</span><span class="lit">1000</span><span class="pun">);</span><span class="pln">
    77. screen</span><span class="pun">.</span><span class="pln">home</span><span class="pun">();</span><span class="pln">
    78. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">" Sweet Dreams "</span><span class="pun">);</span><span class="pln">
    79. screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">);</span><span class="pln">
    80. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"...zzzzzzzzzz..."</span><span class="pun">);</span><span class="pln">
    81. </span><span class="pun">}</span><span class="pln">
    82. </span><span class="kwd">while</span><span class="pln"> </span><span class="pun">(</span><span class="pln">stopAlarm </span><span class="pun">==</span><span class="pln"> LOW</span><span class="pun">)</span><span class="pln">
    83. </span><span class="com">//after the timer reaches zero, this block of code runs until</span><span class="pln">
    84. </span><span class="com">//the user interrupts the signal by pressing the stop button</span><span class="pln">
    85. </span><span class="pun">{</span><span class="pln">
    86. screen</span><span class="pun">.</span><span class="pln">home</span><span class="pun">();</span><span class="pln">
    87. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"TIME TO WAKE UP!"</span><span class="pun">);</span><span class="pln">
    88. screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">);</span><span class="pln">
    89. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"Press Big Button"</span><span class="pun">);</span><span class="pln">
    90. digitalWrite</span><span class="pun">(</span><span class="pln">LED</span><span class="pun">,</span><span class="pln">HIGH</span><span class="pun">);</span><span class="pln">
    91. tone</span><span class="pun">(</span><span class="pln">buzzer</span><span class="pun">,</span><span class="lit">1000</span><span class="pun">);</span><span class="pln">
    92. delay</span><span class="pun">(</span><span class="lit">500</span><span class="pun">);</span><span class="pln">
    93. digitalWrite</span><span class="pun">(</span><span class="pln">LED</span><span class="pun">,</span><span class="pln">LOW</span><span class="pun">);</span><span class="pln">
    94. noTone</span><span class="pun">(</span><span class="pln">buzzer</span><span class="pun">);</span><span class="pln">
    95. delay</span><span class="pun">(</span><span class="lit">500</span><span class="pun">);</span><span class="pln">
    96. setState </span><span class="pun">=</span><span class="pln"> LOW</span><span class="pun">;</span><span class="pln">
    97. </span><span class="pun">}</span><span class="pln">
    98. </span><span class="pun">}</span><span class="pln">
    99. </span><span class="pun">}</span><span class="pln">
    100. </span><span class="com">//following 2 loops change the value of the state values on the</span><span class="pln">
    101. </span><span class="com">//activiation of the interrupt buttons</span><span class="pln">
    102. </span><span class="kwd">void</span><span class="pln"> start</span><span class="pun">(){</span><span class="pln">
    103. setState </span><span class="pun">=!</span><span class="pln"> setState</span><span class="pun">;</span><span class="pln">
    104. </span><span class="pun">}</span><span class="pln">
    105. </span><span class="kwd">void</span><span class="pln"> alarmOff</span><span class="pun">(){</span><span class="pln">
    106. stopAlarm </span><span class="pun">=!</span><span class="pln"> stopAlarm</span><span class="pun">;</span><span class="pln">
    107. </span><span class="pun">}</span>
    <span class="com">/*Wake Me Wake Alarm
    Justin Belardi
    
    Funtionality: 
    The following code uses readings from 2 potentiometers to set values for hours and minutes. 
    Upon the press of the set button, the software sets a timer based on the values from the
    potentiometers. When the timer reaches zero, an LED flashes and a buzzer beeps, prompting 
    the user to wake up. The alarm continues sounding and flahing light until the user presses 
    the stop button located across the room.
    
    Pin Mapping:
    Hour Changer: Pin A0
    Minute Changer: Pin A1
    Set Time Button: Pin 2
    Diasrm Button: Pin 3
    LED: Pin 6
    Buzzer: Pin 9
    
    Credits:
    Intro to Physical Computing Code Byte - Displaying data on an I²C LCD screen 
    -Used for learning how to implement the I2C LCD Screen. 
    -Setup Code for initializing Screen was used in final software for project
    */</span><span class="pln">
    
    </span><span class="com">#include</span><span class="pln"> </span><span class="str"><Wire.h></span><span class="pln">
    </span><span class="com">#include</span><span class="pln"> </span><span class="str"><LiquidCrystal_I2C.h></span><span class="pln">
    
    </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> HRPOT </span><span class="pun">=</span><span class="pln"> A0</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> MINPOT </span><span class="pun">=</span><span class="pln"> A1</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> SETBUT </span><span class="pun">=</span><span class="pln"> </span><span class="lit">2</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> STOPBUT </span><span class="pun">=</span><span class="pln"> </span><span class="lit">3</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> LED </span><span class="pun">=</span><span class="pln"> </span><span class="lit">6</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> buzzer </span><span class="pun">=</span><span class="pln"> </span><span class="lit">9</span><span class="pun">;</span><span class="pln">
    
    </span><span class="com">//Initilize variables used to set timer and countdown</span><span class="pln">
    </span><span class="kwd">int</span><span class="pln"> hrRead </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">int</span><span class="pln"> minRead </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"> 
    </span><span class="kwd">int</span><span class="pln"> hours </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">int</span><span class="pln"> mins </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">int</span><span class="pln"> timer </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">int</span><span class="pln"> hrsLeft </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">int</span><span class="pln"> minLeft </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">int</span><span class="pln"> secLeft </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    
    </span><span class="com">//Initializing state variables that are used to tell the software which </span><span class="pln">
      </span><span class="com">//loop that should be run based on previous code and user input.</span><span class="pln">
    </span><span class="kwd">volatile</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> setState </span><span class="pun">=</span><span class="pln"> LOW</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">volatile</span><span class="pln"> </span><span class="kwd">byte</span><span class="pln"> stopAlarm </span><span class="pun">=</span><span class="pln"> LOW</span><span class="pun">;</span><span class="pln"> 
    
    </span><span class="typ">LiquidCrystal_I2C</span><span class="pln"> screen</span><span class="pun">(</span><span class="lit">0x27</span><span class="pun">,</span><span class="pln"> </span><span class="lit">16</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">);</span><span class="pln">
    
    
    </span><span class="kwd">void</span><span class="pln"> setup</span><span class="pun">(){</span><span class="pln">
      pinMode</span><span class="pun">(</span><span class="pln">HRPOT</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
      pinMode</span><span class="pun">(</span><span class="pln">MINPOT</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
      pinMode</span><span class="pun">(</span><span class="pln">SETBUT</span><span class="pun">,</span><span class="pln"> INPUT_PULLUP</span><span class="pun">);</span><span class="pln">
      attachInterrupt</span><span class="pun">(</span><span class="pln">digitalPinToInterrupt</span><span class="pun">(</span><span class="pln">SETBUT</span><span class="pun">),</span><span class="pln"> start</span><span class="pun">,</span><span class="pln"> RISING</span><span class="pun">);</span><span class="pln">
      pinMode</span><span class="pun">(</span><span class="pln">STOPBUT</span><span class="pun">,</span><span class="pln"> INPUT_PULLUP</span><span class="pun">);</span><span class="pln">
      attachInterrupt</span><span class="pun">(</span><span class="pln">digitalPinToInterrupt</span><span class="pun">(</span><span class="pln">STOPBUT</span><span class="pun">),</span><span class="pln"> alarmOff</span><span class="pun">,</span><span class="pln"> RISING</span><span class="pun">);</span><span class="pln">
      pinMode</span><span class="pun">(</span><span class="pln">LED</span><span class="pun">,</span><span class="pln">OUTPUT</span><span class="pun">);</span><span class="pln">
      </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">(</span><span class="lit">9600</span><span class="pun">);</span><span class="pln">
      
      screen</span><span class="pun">.</span><span class="pln">init</span><span class="pun">();</span><span class="pln">
      screen</span><span class="pun">.</span><span class="pln">backlight</span><span class="pun">();</span><span class="pln">
      screen</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
      
    </span><span class="kwd">void</span><span class="pln"> loop</span><span class="pun">(){</span><span class="pln">
      </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">setState </span><span class="pun">==</span><span class="pln"> LOW</span><span class="pun">){</span><span class="pln"> </span><span class="com">//If the set button has not been pressed yet...</span><span class="pln">
        screen</span><span class="pun">.</span><span class="pln">home</span><span class="pun">();</span><span class="pln">
        screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">" Set Sleep Time "</span><span class="pun">);</span><span class="pln">
        stopAlarm </span><span class="pun">=</span><span class="pln"> LOW</span><span class="pun">;</span><span class="pln">
        hrRead </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">HRPOT</span><span class="pun">);</span><span class="pln">
        minRead </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">MINPOT</span><span class="pun">);</span><span class="pln">
        hours </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">hrRead</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">1023</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">24</span><span class="pun">);</span><span class="pln">
        mins </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">minRead</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">1023</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">60</span><span class="pun">);</span><span class="pln">
        screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">);</span><span class="pln">
        screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">((</span><span class="typ">String</span><span class="pun">)</span><span class="pln"> </span><span class="str">"Hrs: "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> hours </span><span class="pun">+</span><span class="pln"> </span><span class="str">"  Min: "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> mins </span><span class="pun">+</span><span class="str">"  "</span><span class="pun">);</span><span class="pln">  
        timer </span><span class="pun">=</span><span class="pln"> hours</span><span class="pun">*</span><span class="lit">3600</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> mins</span><span class="pun">;</span><span class="pln">
        </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">((</span><span class="typ">String</span><span class="pun">)</span><span class="pln"> </span><span class="str">"Hours: "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> hours </span><span class="pun">+</span><span class="pln"> </span><span class="str">" Minutes: "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> mins</span><span class="pun">);</span><span class="pln">
      </span><span class="pun">}</span><span class="pln">
      </span><span class="kwd">else</span><span class="pun">{</span><span class="pln">
        </span><span class="com">//simulates a timer by looping until a value of zero is reahed</span><span class="pln">
          </span><span class="com">//while reducing time value by 1 and delaying 1000 ms (1 second)</span><span class="pln">
        </span><span class="kwd">while</span><span class="pln"> </span><span class="pun">(</span><span class="pln">timer </span><span class="pun">></span><span class="pln"> </span><span class="lit">0</span><span class="pun">){</span><span class="pln"> 
          timer </span><span class="pun">=</span><span class="pln"> timer </span><span class="pun">-</span><span class="pln"> </span><span class="lit">1</span><span class="pun">;</span><span class="pln">
          </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">timer</span><span class="pun">);</span><span class="pln">
          delay</span><span class="pun">(</span><span class="lit">1000</span><span class="pun">);</span><span class="pln">
          screen</span><span class="pun">.</span><span class="pln">home</span><span class="pun">();</span><span class="pln">
          screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"  Sweet Dreams  "</span><span class="pun">);</span><span class="pln">
          screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">);</span><span class="pln">
          screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"...zzzzzzzzzz..."</span><span class="pun">);</span><span class="pln">  
           
        </span><span class="pun">}</span><span class="pln">
        </span><span class="kwd">while</span><span class="pln"> </span><span class="pun">(</span><span class="pln">stopAlarm </span><span class="pun">==</span><span class="pln"> LOW</span><span class="pun">)</span><span class="pln">
        </span><span class="com">//after the timer reaches zero, this block of code runs until</span><span class="pln">
          </span><span class="com">//the user interrupts the signal by pressing the stop button</span><span class="pln">
        </span><span class="pun">{</span><span class="pln">
          screen</span><span class="pun">.</span><span class="pln">home</span><span class="pun">();</span><span class="pln">
          screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"TIME TO WAKE UP!"</span><span class="pun">);</span><span class="pln">
          screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">);</span><span class="pln">
          screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"Press Big Button"</span><span class="pun">);</span><span class="pln"> 
          digitalWrite</span><span class="pun">(</span><span class="pln">LED</span><span class="pun">,</span><span class="pln">HIGH</span><span class="pun">);</span><span class="pln">
          tone</span><span class="pun">(</span><span class="pln">buzzer</span><span class="pun">,</span><span class="lit">1000</span><span class="pun">);</span><span class="pln">
          delay</span><span class="pun">(</span><span class="lit">500</span><span class="pun">);</span><span class="pln">
          digitalWrite</span><span class="pun">(</span><span class="pln">LED</span><span class="pun">,</span><span class="pln">LOW</span><span class="pun">);</span><span class="pln">
          noTone</span><span class="pun">(</span><span class="pln">buzzer</span><span class="pun">);</span><span class="pln">
          delay</span><span class="pun">(</span><span class="lit">500</span><span class="pun">);</span><span class="pln">
          setState </span><span class="pun">=</span><span class="pln"> LOW</span><span class="pun">;</span><span class="pln">
        </span><span class="pun">}</span><span class="pln">
      </span><span class="pun">}</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
    
    
    </span><span class="com">//following 2 loops change the value of the state values on the</span><span class="pln">
      </span><span class="com">//activiation of the interrupt buttons</span><span class="pln">
    </span><span class="kwd">void</span><span class="pln"> start</span><span class="pun">(){</span><span class="pln">
      setState </span><span class="pun">=!</span><span class="pln"> setState</span><span class="pun">;</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
    
    </span><span class="kwd">void</span><span class="pln"> alarmOff</span><span class="pun">(){</span><span class="pln">
      stopAlarm </span><span class="pun">=!</span><span class="pln"> stopAlarm</span><span class="pun">;</span><span class="pln">
    </span><span class="pun">}</span>