The Pick Alarm encourages practicing while putting a stop to lost picks!

 

Step 1:

“Time to Practice” — The user is prompted to remove the pick and practice.

Step 2:

“Hit the Shed!” — While the user is practicing, a timer counts down one hour.

Step 3:

“Time’s Up!” — After an hour, a buzzer sounds until the pick is put back in its slot.

Step 4:

“Youre done, For today…” — The buzzer will stop once the pick is placed. The following day, the user will be prompted to practice again.

The red light is an indicator that the pick is NOT in its slot.

The green light is an indicator that the pick IS in its slot.

Side view

Process:

A major alteration that I made during my project was implementing the “practice once daily” feature. Originally, after a practice session there was another prompt to practice again. However, I wanted to make it so that the user could only practice once a day. In order to do this, I implemented a DS 3231 clock and majorly altered my finite state machine.

Original FSM

Final FSM

 

 

 

 

 

I would have liked to make my project more compact by using an Arduino nano and soldering my project to a proto board. However, there were no more proto boards or nanos left when I wanted to do this. As a result, I had to create a housing that was much bulkier than my original sketch.

Original sketch

Prototype in progress

 

 

 

 

 

 

Reflection:

Overall, I am proud of my project. First and foremost,  I am really impressed with how simple and effective implementing an FSM was. I  had never tried creating an FSM on a personal project before, but this turned out to be a perfect opportunity. However, my final product did fail to meet some of my expectations and my classmates had comments that reflected these shortcomings. For instance, one student said, “it would be obviously ideal if the ‘guts’ fit inside the box to make it more mobile,” and another said, “the execution needed a bit more time.” These are both valid and I agree with the former whole-heartedly. Although there are times when visibility of wires can be aesthetically pleasing, I don’t think my project benefits from it. In general, the phase I struggled most with was creating a housing. I would like to solder all of the circuitry to a proto board and use an Arduino nano to make the whole project more reliable and compact. Then, I would like to house the project in a clean lazercut box. Another comment that peaked my interest was, “it would be fun if the box pestered you to start practicing.” Many people wondered whether this was a feature and I honestly never thought to add it. In the future, I definitely would like to work it in, especially since so many people assumed it would be included. All in all, I had generally positive feedback saying that my project was a creative solution. It is encouraging to see and I would like to make a new version with all the features I have previously discussed. At the very least, my project will be useful for me. 

 

Code:

  1. <span class="com">/*
  2. * The Pick Alarm
  3. * Created by Connor Maggio
  4. *
  5. * The code below operates the Arduino that is the main funcitonality
  6. * of the alarm. It uses a switch statement to change between states of
  7. * an FSM based on IR LED values. It outputs to an LCD I2C screen,
  8. * a green LED, a red LED, and a Piezo buzzer depending on the state.
  9. * The LCD screen displays a timer that runs via the millis() function.
  10. *
  11. * Pin mapping:
  12. * IR receiver --> A1
  13. * IR transmitter --> D3
  14. * Green LED --> D7
  15. * Red LED --> D8
  16. * Buzzer --> D10
  17. */</span><span class="pln">
  18. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><DS3231.h></span><span class="pln">
  19. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><Wire.h></span><span class="pln">
  20. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><LiquidCrystal_I2C.h></span><span class="pln">
  21. </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">
  22. DS3231 rtc</span><span class="pun">(</span><span class="pln">SDA</span><span class="pun">,</span><span class="pln"> SCL</span><span class="pun">);</span><span class="pln">
  23. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> IR_RX </span><span class="pun">=</span><span class="pln"> A1</span><span class="pun">;</span><span class="pln">
  24. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> IR_TX </span><span class="pun">=</span><span class="pln"> </span><span class="lit">3</span><span class="pun">;</span><span class="pln">
  25. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> LEDG </span><span class="pun">=</span><span class="pln"> </span><span class="lit">7</span><span class="pun">;</span><span class="pln">
  26. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> LEDR </span><span class="pun">=</span><span class="pln"> </span><span class="lit">8</span><span class="pun">;</span><span class="pln">
  27. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> PIEZO </span><span class="pun">=</span><span class="pln"> </span><span class="lit">10</span><span class="pun">;</span><span class="pln">
  28. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> THRESHOLD </span><span class="pun">=</span><span class="pln"> </span><span class="lit">12</span><span class="pun">;</span><span class="pln">
  29. </span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> start</span><span class="pun">;</span><span class="pln">
  30. </span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> timeElapsed</span><span class="pun">;</span><span class="pln">
  31. </span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> startTimer</span><span class="pun">;</span><span class="pln">
  32. </span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> threeSecStart</span><span class="pun">;</span><span class="pln">
  33. </span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> threeSecTimer</span><span class="pun">;</span><span class="pln">
  34. </span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> allSeconds</span><span class="pun">;</span><span class="pln">
  35. </span><span class="kwd">int</span><span class="pln"> minutes</span><span class="pun">;</span><span class="pln">
  36. </span><span class="kwd">int</span><span class="pln"> seconds</span><span class="pun">;</span><span class="pln">
  37. </span><span class="typ">String</span><span class="pln"> dayPracticed</span><span class="pun">;</span><span class="pln">
  38. </span><span class="kwd">bool</span><span class="pln"> pickIn </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  39. </span><span class="kwd">bool</span><span class="pln"> pickSet </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  40. </span><span class="kwd">bool</span><span class="pln"> timerDone </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  41. </span><span class="kwd">bool</span><span class="pln"> threeSecDone </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  42. </span><span class="kwd">bool</span><span class="pln"> newDay </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  43. </span><span class="kwd">bool</span><span class="pln"> alarmOn </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  44. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> INIT </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  45. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> SETUP </span><span class="pun">=</span><span class="pln"> </span><span class="lit">1</span><span class="pun">;</span><span class="pln">
  46. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> MODE_IDLE </span><span class="pun">=</span><span class="pln"> </span><span class="lit">2</span><span class="pun">;</span><span class="pln">
  47. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> MODE_RUNNING </span><span class="pun">=</span><span class="pln"> </span><span class="lit">3</span><span class="pun">;</span><span class="pln">
  48. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> MODE_DONE </span><span class="pun">=</span><span class="pln"> </span><span class="lit">4</span><span class="pun">;</span><span class="pln">
  49. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> MODE_RINGING </span><span class="pun">=</span><span class="pln"> </span><span class="lit">5</span><span class="pun">;</span><span class="pln">
  50. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> MODE_TMRW </span><span class="pun">=</span><span class="pln"> </span><span class="lit">6</span><span class="pun">;</span><span class="pln">
  51. </span><span class="kwd">int</span><span class="pln"> currentMode </span><span class="pun">=</span><span class="pln"> INIT</span><span class="pun">;</span><span class="pln">
  52. </span><span class="kwd">void</span><span class="pln"> setup</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  53. </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">
  54. pinMode</span><span class="pun">(</span><span class="pln">IR_RX</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
  55. pinMode</span><span class="pun">(</span><span class="pln">IR_TX</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  56. pinMode</span><span class="pun">(</span><span class="pln">LEDG</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  57. pinMode</span><span class="pun">(</span><span class="pln">LEDR</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  58. pinMode</span><span class="pun">(</span><span class="pln">PIEZO</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  59. </span><span class="com">// Initialize the rtc object</span><span class="pln">
  60. rtc</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">();</span><span class="pln">
  61. rtc</span><span class="pun">.</span><span class="pln">setDOW</span><span class="pun">(</span><span class="pln">TUESDAY</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Set Day-of-Week to SUNDAY</span><span class="pln">
  62. rtc</span><span class="pun">.</span><span class="pln">setTime</span><span class="pun">(</span><span class="lit">23</span><span class="pun">,</span><span class="pln"> </span><span class="lit">59</span><span class="pun">,</span><span class="pln"> </span><span class="lit">00</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Set the time to 12:00:00 (24hr format)</span><span class="pln">
  63. rtc</span><span class="pun">.</span><span class="pln">setDate</span><span class="pun">(</span><span class="lit">3</span><span class="pun">,</span><span class="pln"> </span><span class="lit">5</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2019</span><span class="pun">);</span><span class="pln"> </span><span class="com">// Set the date to January 1st, 2014</span><span class="pln">
  64. screen</span><span class="pun">.</span><span class="pln">init</span><span class="pun">();</span><span class="pln">
  65. screen</span><span class="pun">.</span><span class="pln">backlight</span><span class="pun">();</span><span class="pln">
  66. screen</span><span class="pun">.</span><span class="pln">home</span><span class="pun">();</span><span class="pln">
  67. start </span><span class="pun">=</span><span class="pln"> millis</span><span class="pun">();</span><span class="pln">
  68. delay</span><span class="pun">(</span><span class="lit">500</span><span class="pun">);</span><span class="pln">
  69. </span><span class="pun">}</span><span class="pln">
  70. </span><span class="kwd">void</span><span class="pln"> loop</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  71. </span><span class="kwd">int</span><span class="pln"> IR_received</span><span class="pun">;</span><span class="pln">
  72. analogWrite</span><span class="pun">(</span><span class="pln">IR_TX</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1023</span><span class="pun">);</span><span class="pln">
  73. IR_received </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">IR_RX</span><span class="pun">);</span><span class="pln">
  74. </span><span class="com">// Serial.println(IR_received);</span><span class="pln">
  75. </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="pln">rtc</span><span class="pun">.</span><span class="pln">getDOWStr</span><span class="pun">());</span><span class="pln">
  76. </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">rtc</span><span class="pun">.</span><span class="pln">getTimeStr</span><span class="pun">());</span><span class="pln">
  77. </span><span class="com">/*
  78. * LED Management
  79. */</span><span class="pln">
  80. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">pickSet </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  81. digitalWrite</span><span class="pun">(</span><span class="pln">LEDG</span><span class="pun">,</span><span class="pln"> HIGH</span><span class="pun">);</span><span class="pln">
  82. digitalWrite</span><span class="pun">(</span><span class="pln">LEDR</span><span class="pun">,</span><span class="pln"> LOW</span><span class="pun">);</span><span class="pln">
  83. </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  84. digitalWrite</span><span class="pun">(</span><span class="pln">LEDR</span><span class="pun">,</span><span class="pln"> HIGH</span><span class="pun">);</span><span class="pln">
  85. digitalWrite</span><span class="pun">(</span><span class="pln">LEDG</span><span class="pun">,</span><span class="pln"> LOW</span><span class="pun">);</span><span class="pln">
  86. </span><span class="pun">}</span><span class="pln">
  87. </span><span class="com">/*
  88. * Timer Management
  89. */</span><span class="pln">
  90. </span><span class="kwd">int</span><span class="pln"> secsRemaining </span><span class="pun">=</span><span class="pln"> allSeconds</span><span class="pun">%</span><span class="lit">3600</span><span class="pun">;</span><span class="pln">
  91. </span><span class="kwd">int</span><span class="pln"> runMinutes </span><span class="pun">=</span><span class="pln"> secsRemaining</span><span class="pun">/</span><span class="lit">60</span><span class="pun">;</span><span class="pln">
  92. </span><span class="kwd">int</span><span class="pln"> runSeconds </span><span class="pun">=</span><span class="pln"> secsRemaining</span><span class="pun">%</span><span class="lit">60</span><span class="pun">;</span><span class="pln">
  93. </span><span class="kwd">int</span><span class="pln"> downMinutes </span><span class="pun">=</span><span class="pln"> </span><span class="lit">59</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> runMinutes</span><span class="pun">;</span><span class="pln">
  94. </span><span class="kwd">int</span><span class="pln"> downSeconds </span><span class="pun">=</span><span class="pln"> </span><span class="lit">59</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> runSeconds</span><span class="pun">;</span><span class="pln">
  95. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">runSeconds </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">30</span><span class="pun">)</span><span class="pln">
  96. </span><span class="pun">{</span><span class="pln">
  97. timerDone </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
  98. </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  99. timerDone </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  100. </span><span class="pun">}</span><span class="pln">
  101. </span><span class="com">/*
  102. * Day Management
  103. */</span><span class="pln">
  104. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">dayPracticed</span><span class="pun">.</span><span class="pln">equals</span><span class="pun">(</span><span class="pln">rtc</span><span class="pun">.</span><span class="pln">getDOWStr</span><span class="pun">(</span><span class="pln">FORMAT_SHORT</span><span class="pun">))</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">)</span><span class="pln">
  105. </span><span class="pun">{</span><span class="pln">
  106. newDay </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
  107. </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  108. newDay </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  109. </span><span class="pun">}</span><span class="pln">
  110. </span><span class="com">/*
  111. * Pick Setup
  112. */</span><span class="pln">
  113. pickIn </span><span class="pun">=</span><span class="pln"> IR_received </span><span class="pun"><</span><span class="pln"> THRESHOLD</span><span class="pun">;</span><span class="pln">
  114. </span><span class="com">//Serial.println(pickIn);</span><span class="pln">
  115. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">pickIn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
  116. </span><span class="pun">{</span><span class="pln">
  117. pickSet </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
  118. </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  119. pickSet </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  120. </span><span class="pun">}</span><span class="pln">
  121. </span><span class="com">/*
  122. * Pick Detection
  123. */</span><span class="pln">
  124. pickIn </span><span class="pun">=</span><span class="pln"> IR_received </span><span class="pun"><</span><span class="pln"> THRESHOLD</span><span class="pun">;</span><span class="pln">
  125. </span><span class="com">// Serial.println(pickIn);</span><span class="pln">
  126. </span><span class="com">/*
  127. * Alarm Management
  128. */</span><span class="pln">
  129. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">alarmOn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
  130. </span><span class="pun">{</span><span class="pln">
  131. tone</span><span class="pun">(</span><span class="pln">PIEZO</span><span class="pun">,</span><span class="pln"> </span><span class="lit">440</span><span class="pun">,</span><span class="pln"> </span><span class="lit">250</span><span class="pun">);</span><span class="pln">
  132. delay</span><span class="pun">(</span><span class="lit">1000</span><span class="pun">);</span><span class="pln">
  133. </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">//alarm is off</span><span class="pln">
  134. noTone</span><span class="pun">(</span><span class="pln">PIEZO</span><span class="pun">);</span><span class="pln">
  135. </span><span class="pun">}</span><span class="pln">
  136. </span><span class="com">/*
  137. * Mode Management
  138. */</span><span class="pln">
  139. </span><span class="kwd">switch</span><span class="pun">(</span><span class="pln">currentMode</span><span class="pun">)</span><span class="pln">
  140. </span><span class="pun">{</span><span class="pln">
  141. </span><span class="kwd">case</span><span class="pln"> INIT</span><span class="pun">:</span><span class="pln">
  142. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">pickSet </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">)</span><span class="pln">
  143. </span><span class="pun">{</span><span class="pln">
  144. currentMode </span><span class="pun">=</span><span class="pln"> SETUP</span><span class="pun">;</span><span class="pln">
  145. </span><span class="pun">}</span><span class="pln">
  146. </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
  147. </span><span class="kwd">case</span><span class="pln"> SETUP</span><span class="pun">:</span><span class="pln">
  148. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">pickSet </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
  149. </span><span class="pun">{</span><span class="pln">
  150. screen</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">
  151. currentMode </span><span class="pun">=</span><span class="pln"> MODE_IDLE</span><span class="pun">;</span><span class="pln">
  152. </span><span class="pun">}</span><span class="pln">
  153. </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
  154. </span><span class="kwd">case</span><span class="pln"> MODE_IDLE</span><span class="pun">:</span><span class="pln">
  155. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">pickIn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">)</span><span class="pln">
  156. </span><span class="pun">{</span><span class="pln">
  157. screen</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">
  158. startTimer </span><span class="pun">=</span><span class="pln"> millis</span><span class="pun">();</span><span class="pln">
  159. currentMode </span><span class="pun">=</span><span class="pln"> MODE_RUNNING</span><span class="pun">;</span><span class="pln">
  160. </span><span class="pun">}</span><span class="pln">
  161. </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
  162. </span><span class="kwd">case</span><span class="pln"> MODE_RUNNING</span><span class="pun">:</span><span class="pln">
  163. allSeconds </span><span class="pun">=</span><span class="pln"> </span><span class="pun">(</span><span class="pln">millis</span><span class="pun">()</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> startTimer</span><span class="pun">)/</span><span class="lit">1000</span><span class="pun">;</span><span class="pln">
  164. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">pickIn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
  165. </span><span class="pun">{</span><span class="pln">
  166. screen</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">
  167. threeSecStart </span><span class="pun">=</span><span class="pln"> millis</span><span class="pun">();</span><span class="pln">
  168. currentMode </span><span class="pun">=</span><span class="pln"> MODE_DONE</span><span class="pun">;</span><span class="pln">
  169. </span><span class="pun">}</span><span class="pln">
  170. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">timerDone </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
  171. </span><span class="pun">{</span><span class="pln">
  172. allSeconds </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  173. screen</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">
  174. currentMode </span><span class="pun">=</span><span class="pln"> MODE_RINGING</span><span class="pun">;</span><span class="pln">
  175. </span><span class="pun">}</span><span class="pln">
  176. </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
  177. </span><span class="kwd">case</span><span class="pln"> MODE_DONE</span><span class="pun">:</span><span class="pln">
  178. threeSecTimer </span><span class="pun">=</span><span class="pln"> </span><span class="pun">(</span><span class="pln">millis</span><span class="pun">()</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> threeSecStart</span><span class="pun">)/</span><span class="lit">1000</span><span class="pun">;</span><span class="pln">
  179. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">pickIn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">)</span><span class="pln">
  180. </span><span class="pun">{</span><span class="pln">
  181. screen</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">
  182. threeSecStart </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  183. threeSecTimer </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  184. currentMode </span><span class="pun">=</span><span class="pln"> MODE_RUNNING</span><span class="pun">;</span><span class="pln">
  185. </span><span class="pun">}</span><span class="pln">
  186. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">threeSecTimer </span><span class="pun">></span><span class="pln"> </span><span class="lit">3</span><span class="pun">)</span><span class="pln">
  187. </span><span class="pun">{</span><span class="pln">
  188. screen</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">
  189. allSeconds </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  190. threeSecStart </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  191. threeSecTimer </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  192. dayPracticed </span><span class="pun">=</span><span class="pln"> rtc</span><span class="pun">.</span><span class="pln">getDOWStr</span><span class="pun">(</span><span class="pln">FORMAT_SHORT</span><span class="pun">);</span><span class="pln">
  193. currentMode </span><span class="pun">=</span><span class="pln"> MODE_TMRW</span><span class="pun">;</span><span class="pln">
  194. </span><span class="pun">}</span><span class="pln">
  195. </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
  196. </span><span class="kwd">case</span><span class="pln"> MODE_RINGING</span><span class="pun">:</span><span class="pln">
  197. alarmOn </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
  198. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">pickIn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
  199. </span><span class="pun">{</span><span class="pln">
  200. alarmOn </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  201. screen</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">
  202. dayPracticed </span><span class="pun">=</span><span class="pln"> rtc</span><span class="pun">.</span><span class="pln">getDOWStr</span><span class="pun">(</span><span class="pln">FORMAT_SHORT</span><span class="pun">);</span><span class="pln">
  203. currentMode </span><span class="pun">=</span><span class="pln"> MODE_TMRW</span><span class="pun">;</span><span class="pln">
  204. </span><span class="pun">}</span><span class="pln">
  205. </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
  206. </span><span class="kwd">case</span><span class="pln"> MODE_TMRW</span><span class="pun">:</span><span class="pln">
  207. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">newDay </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
  208. </span><span class="pun">{</span><span class="pln">
  209. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">pickIn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
  210. </span><span class="pun">{</span><span class="pln">
  211. screen</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">
  212. currentMode </span><span class="pun">=</span><span class="pln"> MODE_IDLE</span><span class="pun">;</span><span class="pln">
  213. </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">//pickIn == false</span><span class="pln">
  214. screen</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">
  215. currentMode </span><span class="pun">=</span><span class="pln"> SETUP</span><span class="pun">;</span><span class="pln">
  216. </span><span class="pun">}</span><span class="pln">
  217. </span><span class="pun">}</span><span class="pln">
  218. </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
  219. </span><span class="pun">}</span><span class="pln">
  220. </span><span class="com">/*
  221. * LCD Management
  222. */</span><span class="pln">
  223. </span><span class="kwd">char</span><span class="pln"> buf</span><span class="pun">[</span><span class="lit">9</span><span class="pun">];</span><span class="pln">
  224. sprintf</span><span class="pun">(</span><span class="pln">buf</span><span class="pun">,</span><span class="pln"> </span><span class="str">"%02d:%02d"</span><span class="pun">,</span><span class="pln"> downMinutes</span><span class="pun">,</span><span class="pln"> downSeconds</span><span class="pun">);</span><span class="pln">
  225. </span><span class="kwd">char</span><span class="pln"> </span><span class="kwd">def</span><span class="pun">[</span><span class="lit">9</span><span class="pun">];</span><span class="pln">
  226. sprintf</span><span class="pun">(</span><span class="kwd">def</span><span class="pun">,</span><span class="pln"> </span><span class="str">"%02d:%02d"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">60</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  227. </span><span class="kwd">switch</span><span class="pun">(</span><span class="pln">currentMode</span><span class="pun">)</span><span class="pln">
  228. </span><span class="pun">{</span><span class="pln">
  229. </span><span class="kwd">case</span><span class="pln"> INIT</span><span class="pun">:</span><span class="pln">
  230. </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
  231. </span><span class="kwd">case</span><span class="pln"> SETUP</span><span class="pun">:</span><span class="pln">
  232. screen</span><span class="pun">.</span><span class="pln">home</span><span class="pun">();</span><span class="pln">
  233. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"Insert your Pick"</span><span class="pun">);</span><span class="pln">
  234. 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="lit">1</span><span class="pun">);</span><span class="pln">
  235. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"to get started!"</span><span class="pun">);</span><span class="pln">
  236. </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
  237. </span><span class="kwd">case</span><span class="pln"> MODE_IDLE</span><span class="pun">:</span><span class="pln">
  238. screen</span><span class="pun">.</span><span class="pln">home</span><span class="pun">();</span><span class="pln">
  239. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"Time to Practice"</span><span class="pun">);</span><span class="pln">
  240. screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="pln">lcdCenter</span><span class="pun">(</span><span class="lit">5</span><span class="pun">),</span><span class="lit">1</span><span class="pun">);</span><span class="pln">
  241. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="kwd">def</span><span class="pun">);</span><span class="pln">
  242. </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
  243. </span><span class="kwd">case</span><span class="pln"> MODE_RUNNING</span><span class="pun">:</span><span class="pln">
  244. screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="pln">lcdCenter</span><span class="pun">(</span><span class="lit">13</span><span class="pun">),</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  245. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"Hit the Shed!"</span><span class="pun">);</span><span class="pln">
  246. screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="pln">lcdCenter</span><span class="pun">(</span><span class="lit">5</span><span class="pun">),</span><span class="lit">1</span><span class="pun">);</span><span class="pln">
  247. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="pln">buf</span><span class="pun">);</span><span class="pln">
  248. </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
  249. </span><span class="kwd">case</span><span class="pln"> MODE_DONE</span><span class="pun">:</span><span class="pln">
  250. screen</span><span class="pun">.</span><span class="pln">home</span><span class="pun">();</span><span class="pln">
  251. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"Are you done?"</span><span class="pun">);</span><span class="pln">
  252. screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="pln">lcdCenter</span><span class="pun">(</span><span class="lit">14</span><span class="pun">),</span><span class="lit">1</span><span class="pun">);</span><span class="pln">
  253. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"Leave the Pick"</span><span class="pun">);</span><span class="pln">
  254. </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
  255. </span><span class="kwd">case</span><span class="pln"> MODE_RINGING</span><span class="pun">:</span><span class="pln">
  256. screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="pln">lcdCenter</span><span class="pun">(</span><span class="lit">10</span><span class="pun">),</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  257. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"Time's Up!"</span><span class="pun">);</span><span class="pln">
  258. screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="pln">lcdCenter</span><span class="pun">(</span><span class="lit">5</span><span class="pun">),</span><span class="lit">1</span><span class="pun">);</span><span class="pln">
  259. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"00:00"</span><span class="pun">);</span><span class="pln">
  260. </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
  261. </span><span class="kwd">case</span><span class="pln"> MODE_TMRW</span><span class="pun">:</span><span class="pln">
  262. screen</span><span class="pun">.</span><span class="pln">home</span><span class="pun">();</span><span class="pln">
  263. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"You're done!"</span><span class="pun">);</span><span class="pln">
  264. screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="pln">lcdCenter</span><span class="pun">(</span><span class="lit">12</span><span class="pun">),</span><span class="lit">1</span><span class="pun">);</span><span class="pln">
  265. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"For today..."</span><span class="pun">);</span><span class="pln">
  266. </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
  267. </span><span class="pun">}</span><span class="pln">
  268. </span><span class="pun">}</span><span class="pln">
  269. </span><span class="kwd">int</span><span class="pln"> lcdCenter</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> stringSize</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  270. </span><span class="kwd">int</span><span class="pln"> buf </span><span class="pun">=</span><span class="pln"> stringSize</span><span class="pun">%</span><span class="lit">2</span><span class="pun">;</span><span class="pln">
  271. </span><span class="kwd">return</span><span class="pln"> </span><span class="lit">8</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> </span><span class="pun">(</span><span class="pln">stringSize</span><span class="pun">/</span><span class="lit">2</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> buf</span><span class="pun">);</span><span class="pln">
  272. </span><span class="pun">}</span>
<span class="com">/*
 * The Pick Alarm
 * Created by Connor Maggio
 * 
 * The code below operates the Arduino that is the main funcitonality 
 * of the alarm. It uses a switch statement to change between states of 
 * an FSM based on IR LED values. It outputs to an LCD I2C screen, 
 * a green LED, a red LED, and a Piezo buzzer depending on the state. 
 * The LCD screen displays a timer that runs via the millis() function.
 * 
 * Pin mapping:
 * IR receiver --> A1
 * IR transmitter --> D3
 * Green LED --> D7
 * Red LED --> D8
 * Buzzer --> D10
 */</span><span class="pln">

</span><span class="com">#include</span><span class="pln"> </span><span class="str"><DS3231.h></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="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">
DS3231  rtc</span><span class="pun">(</span><span class="pln">SDA</span><span class="pun">,</span><span class="pln"> SCL</span><span class="pun">);</span><span class="pln">

</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> IR_RX </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">int</span><span class="pln"> IR_TX </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">int</span><span class="pln"> LEDG </span><span class="pun">=</span><span class="pln"> </span><span class="lit">7</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> LEDR </span><span class="pun">=</span><span class="pln"> </span><span class="lit">8</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> PIEZO </span><span class="pun">=</span><span class="pln"> </span><span class="lit">10</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> THRESHOLD </span><span class="pun">=</span><span class="pln"> </span><span class="lit">12</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> start</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> timeElapsed</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> startTimer</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> threeSecStart</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> threeSecTimer</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> allSeconds</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> minutes</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> seconds</span><span class="pun">;</span><span class="pln">

</span><span class="typ">String</span><span class="pln"> dayPracticed</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">bool</span><span class="pln"> pickIn </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">bool</span><span class="pln"> pickSet </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">bool</span><span class="pln"> timerDone </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">bool</span><span class="pln"> threeSecDone </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">bool</span><span class="pln"> newDay </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">bool</span><span class="pln"> alarmOn </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> INIT </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">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> SETUP </span><span class="pun">=</span><span class="pln"> </span><span class="lit">1</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> MODE_IDLE </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">int</span><span class="pln"> MODE_RUNNING </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">int</span><span class="pln"> MODE_DONE </span><span class="pun">=</span><span class="pln"> </span><span class="lit">4</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> MODE_RINGING </span><span class="pun">=</span><span class="pln"> </span><span class="lit">5</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> MODE_TMRW </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">int</span><span class="pln"> currentMode </span><span class="pun">=</span><span class="pln"> INIT</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"> </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">
  pinMode</span><span class="pun">(</span><span class="pln">IR_RX</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">IR_TX</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  pinMode</span><span class="pun">(</span><span class="pln">LEDG</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  pinMode</span><span class="pun">(</span><span class="pln">LEDR</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  pinMode</span><span class="pun">(</span><span class="pln">PIEZO</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">

  </span><span class="com">// Initialize the rtc object</span><span class="pln">
  rtc</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">();</span><span class="pln">
  rtc</span><span class="pun">.</span><span class="pln">setDOW</span><span class="pun">(</span><span class="pln">TUESDAY</span><span class="pun">);</span><span class="pln">     </span><span class="com">// Set Day-of-Week to SUNDAY</span><span class="pln">
  rtc</span><span class="pun">.</span><span class="pln">setTime</span><span class="pun">(</span><span class="lit">23</span><span class="pun">,</span><span class="pln"> </span><span class="lit">59</span><span class="pun">,</span><span class="pln"> </span><span class="lit">00</span><span class="pun">);</span><span class="pln">     </span><span class="com">// Set the time to 12:00:00 (24hr format)</span><span class="pln">
  rtc</span><span class="pun">.</span><span class="pln">setDate</span><span class="pun">(</span><span class="lit">3</span><span class="pun">,</span><span class="pln"> </span><span class="lit">5</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2019</span><span class="pun">);</span><span class="pln">   </span><span class="com">// Set the date to January 1st, 2014</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">home</span><span class="pun">();</span><span class="pln">
  start </span><span class="pun">=</span><span class="pln"> millis</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">
</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="pun">{</span><span class="pln">
  </span><span class="kwd">int</span><span class="pln"> IR_received</span><span class="pun">;</span><span class="pln">
  analogWrite</span><span class="pun">(</span><span class="pln">IR_TX</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1023</span><span class="pun">);</span><span class="pln">
  IR_received </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">IR_RX</span><span class="pun">);</span><span class="pln">
</span><span class="com">//  Serial.println(IR_received);</span><span class="pln">
  </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="pln">rtc</span><span class="pun">.</span><span class="pln">getDOWStr</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">rtc</span><span class="pun">.</span><span class="pln">getTimeStr</span><span class="pun">());</span><span class="pln">
  
  </span><span class="com">/*
   * LED Management
   */</span><span class="pln">
   </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">pickSet </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    digitalWrite</span><span class="pun">(</span><span class="pln">LEDG</span><span class="pun">,</span><span class="pln"> HIGH</span><span class="pun">);</span><span class="pln">
    digitalWrite</span><span class="pun">(</span><span class="pln">LEDR</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="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    digitalWrite</span><span class="pun">(</span><span class="pln">LEDR</span><span class="pun">,</span><span class="pln"> HIGH</span><span class="pun">);</span><span class="pln">
    digitalWrite</span><span class="pun">(</span><span class="pln">LEDG</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="com">/*
   * Timer Management
   */</span><span class="pln">
  </span><span class="kwd">int</span><span class="pln"> secsRemaining </span><span class="pun">=</span><span class="pln"> allSeconds</span><span class="pun">%</span><span class="lit">3600</span><span class="pun">;</span><span class="pln">
  </span><span class="kwd">int</span><span class="pln"> runMinutes </span><span class="pun">=</span><span class="pln"> secsRemaining</span><span class="pun">/</span><span class="lit">60</span><span class="pun">;</span><span class="pln">
  </span><span class="kwd">int</span><span class="pln"> runSeconds </span><span class="pun">=</span><span class="pln"> secsRemaining</span><span class="pun">%</span><span class="lit">60</span><span class="pun">;</span><span class="pln">

  </span><span class="kwd">int</span><span class="pln"> downMinutes </span><span class="pun">=</span><span class="pln"> </span><span class="lit">59</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> runMinutes</span><span class="pun">;</span><span class="pln">
  </span><span class="kwd">int</span><span class="pln"> downSeconds </span><span class="pun">=</span><span class="pln"> </span><span class="lit">59</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> runSeconds</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">runSeconds </span><span class="pun">>=</span><span class="pln"> </span><span class="lit">30</span><span class="pun">)</span><span class="pln">
  </span><span class="pun">{</span><span class="pln">
    timerDone </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
  </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    timerDone </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">

  </span><span class="com">/*
   * Day Management
   */</span><span class="pln">
   </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">dayPracticed</span><span class="pun">.</span><span class="pln">equals</span><span class="pun">(</span><span class="pln">rtc</span><span class="pun">.</span><span class="pln">getDOWStr</span><span class="pun">(</span><span class="pln">FORMAT_SHORT</span><span class="pun">))</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">)</span><span class="pln">
   </span><span class="pun">{</span><span class="pln">
     newDay </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
   </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
     newDay </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
   </span><span class="pun">}</span><span class="pln">

  </span><span class="com">/*
   * Pick Setup
   */</span><span class="pln">
   pickIn </span><span class="pun">=</span><span class="pln"> IR_received </span><span class="pun"><</span><span class="pln"> THRESHOLD</span><span class="pun">;</span><span class="pln">
   </span><span class="com">//Serial.println(pickIn);</span><span class="pln">
   </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">pickIn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
   </span><span class="pun">{</span><span class="pln">
    pickSet </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
   </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    pickSet </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
   </span><span class="pun">}</span><span class="pln">

  </span><span class="com">/*
   * Pick Detection
   */</span><span class="pln">
   pickIn </span><span class="pun">=</span><span class="pln"> IR_received </span><span class="pun"><</span><span class="pln"> THRESHOLD</span><span class="pun">;</span><span class="pln">
</span><span class="com">//   Serial.println(pickIn);</span><span class="pln">

  </span><span class="com">/*
   * Alarm Management
   */</span><span class="pln">
   </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">alarmOn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
   </span><span class="pun">{</span><span class="pln">
     tone</span><span class="pun">(</span><span class="pln">PIEZO</span><span class="pun">,</span><span class="pln"> </span><span class="lit">440</span><span class="pun">,</span><span class="pln"> </span><span class="lit">250</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">
   </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">//alarm is off</span><span class="pln">
     noTone</span><span class="pun">(</span><span class="pln">PIEZO</span><span class="pun">);</span><span class="pln">
   </span><span class="pun">}</span><span class="pln">

   
  </span><span class="com">/*
   * Mode Management
   */</span><span class="pln">
  </span><span class="kwd">switch</span><span class="pun">(</span><span class="pln">currentMode</span><span class="pun">)</span><span class="pln">
  </span><span class="pun">{</span><span class="pln">
    </span><span class="kwd">case</span><span class="pln"> INIT</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">pickSet </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">)</span><span class="pln">
      </span><span class="pun">{</span><span class="pln">
        currentMode </span><span class="pun">=</span><span class="pln"> SETUP</span><span class="pun">;</span><span class="pln">
      </span><span class="pun">}</span><span class="pln">
      </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">case</span><span class="pln"> SETUP</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">pickSet </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
      </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">
        currentMode </span><span class="pun">=</span><span class="pln"> MODE_IDLE</span><span class="pun">;</span><span class="pln">
      </span><span class="pun">}</span><span class="pln">
      </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">case</span><span class="pln"> MODE_IDLE</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">pickIn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">)</span><span class="pln">
      </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">
        startTimer </span><span class="pun">=</span><span class="pln"> millis</span><span class="pun">();</span><span class="pln">
        currentMode </span><span class="pun">=</span><span class="pln"> MODE_RUNNING</span><span class="pun">;</span><span class="pln">
      </span><span class="pun">}</span><span class="pln">
      </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">case</span><span class="pln"> MODE_RUNNING</span><span class="pun">:</span><span class="pln">
      allSeconds </span><span class="pun">=</span><span class="pln"> </span><span class="pun">(</span><span class="pln">millis</span><span class="pun">()</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> startTimer</span><span class="pun">)/</span><span class="lit">1000</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">pickIn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
        </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">
          threeSecStart </span><span class="pun">=</span><span class="pln"> millis</span><span class="pun">();</span><span class="pln">
          currentMode </span><span class="pun">=</span><span class="pln"> MODE_DONE</span><span class="pun">;</span><span class="pln">
        </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">timerDone </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
      </span><span class="pun">{</span><span class="pln">
        allSeconds </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</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">
        currentMode </span><span class="pun">=</span><span class="pln"> MODE_RINGING</span><span class="pun">;</span><span class="pln">
      </span><span class="pun">}</span><span class="pln">
      </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">case</span><span class="pln"> MODE_DONE</span><span class="pun">:</span><span class="pln">
      threeSecTimer </span><span class="pun">=</span><span class="pln"> </span><span class="pun">(</span><span class="pln">millis</span><span class="pun">()</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> threeSecStart</span><span class="pun">)/</span><span class="lit">1000</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">pickIn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">)</span><span class="pln">
        </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">
          threeSecStart </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
          threeSecTimer </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
          currentMode </span><span class="pun">=</span><span class="pln"> MODE_RUNNING</span><span class="pun">;</span><span class="pln">
        </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">threeSecTimer </span><span class="pun">></span><span class="pln"> </span><span class="lit">3</span><span class="pun">)</span><span class="pln">
        </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">
          allSeconds </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
          threeSecStart </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
          threeSecTimer </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
          dayPracticed </span><span class="pun">=</span><span class="pln"> rtc</span><span class="pun">.</span><span class="pln">getDOWStr</span><span class="pun">(</span><span class="pln">FORMAT_SHORT</span><span class="pun">);</span><span class="pln">
          currentMode </span><span class="pun">=</span><span class="pln"> MODE_TMRW</span><span class="pun">;</span><span class="pln">
        </span><span class="pun">}</span><span class="pln">
      </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">case</span><span class="pln"> MODE_RINGING</span><span class="pun">:</span><span class="pln">
      alarmOn </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</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">pickIn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
      </span><span class="pun">{</span><span class="pln">
        alarmOn </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</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">
        dayPracticed </span><span class="pun">=</span><span class="pln"> rtc</span><span class="pun">.</span><span class="pln">getDOWStr</span><span class="pun">(</span><span class="pln">FORMAT_SHORT</span><span class="pun">);</span><span class="pln">
        currentMode </span><span class="pun">=</span><span class="pln"> MODE_TMRW</span><span class="pun">;</span><span class="pln">
      </span><span class="pun">}</span><span class="pln">
      </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">case</span><span class="pln"> MODE_TMRW</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">newDay </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
        </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">pickIn </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">)</span><span class="pln">
          </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">
            currentMode </span><span class="pun">=</span><span class="pln"> MODE_IDLE</span><span class="pun">;</span><span class="pln">
          </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">//pickIn == false</span><span class="pln">
            screen</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">
            currentMode </span><span class="pun">=</span><span class="pln"> SETUP</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="kwd">break</span><span class="pun">;</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">

  </span><span class="com">/*
   * LCD Management
   */</span><span class="pln">
  </span><span class="kwd">char</span><span class="pln"> buf</span><span class="pun">[</span><span class="lit">9</span><span class="pun">];</span><span class="pln">
  sprintf</span><span class="pun">(</span><span class="pln">buf</span><span class="pun">,</span><span class="pln"> </span><span class="str">"%02d:%02d"</span><span class="pun">,</span><span class="pln"> downMinutes</span><span class="pun">,</span><span class="pln"> downSeconds</span><span class="pun">);</span><span class="pln">

  </span><span class="kwd">char</span><span class="pln"> </span><span class="kwd">def</span><span class="pun">[</span><span class="lit">9</span><span class="pun">];</span><span class="pln">
  sprintf</span><span class="pun">(</span><span class="kwd">def</span><span class="pun">,</span><span class="pln"> </span><span class="str">"%02d:%02d"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">60</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">switch</span><span class="pun">(</span><span class="pln">currentMode</span><span class="pun">)</span><span class="pln">
  </span><span class="pun">{</span><span class="pln">
    </span><span class="kwd">case</span><span class="pln"> INIT</span><span class="pun">:</span><span class="pln">
      </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">case</span><span class="pln"> SETUP</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">"Insert your Pick"</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="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">"to get started!"</span><span class="pun">);</span><span class="pln">
      </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">case</span><span class="pln"> MODE_IDLE</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 Practice"</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="pln">lcdCenter</span><span class="pun">(</span><span class="lit">5</span><span class="pun">),</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="kwd">def</span><span class="pun">);</span><span class="pln">
      </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">case</span><span class="pln"> MODE_RUNNING</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="pln">lcdCenter</span><span class="pun">(</span><span class="lit">13</span><span class="pun">),</span><span class="lit">0</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">"Hit the Shed!"</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="pln">lcdCenter</span><span class="pun">(</span><span class="lit">5</span><span class="pun">),</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="pln">buf</span><span class="pun">);</span><span class="pln">
      </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">case</span><span class="pln"> MODE_DONE</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">"Are you done?"</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="pln">lcdCenter</span><span class="pun">(</span><span class="lit">14</span><span class="pun">),</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">"Leave the Pick"</span><span class="pun">);</span><span class="pln">
      </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">case</span><span class="pln"> MODE_RINGING</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="pln">lcdCenter</span><span class="pun">(</span><span class="lit">10</span><span class="pun">),</span><span class="lit">0</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's 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="pln">lcdCenter</span><span class="pun">(</span><span class="lit">5</span><span class="pun">),</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">"00:00"</span><span class="pun">);</span><span class="pln">
      </span><span class="kwd">break</span><span class="pun">;</span><span class="pln">
    </span><span class="kwd">case</span><span class="pln"> MODE_TMRW</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">"You're done!"</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="pln">lcdCenter</span><span class="pun">(</span><span class="lit">12</span><span class="pun">),</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">"For today..."</span><span class="pun">);</span><span class="pln">
      </span><span class="kwd">break</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="kwd">int</span><span class="pln"> lcdCenter</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> stringSize</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="kwd">int</span><span class="pln"> buf </span><span class="pun">=</span><span class="pln"> stringSize</span><span class="pun">%</span><span class="lit">2</span><span class="pun">;</span><span class="pln">
  </span><span class="kwd">return</span><span class="pln"> </span><span class="lit">8</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> </span><span class="pun">(</span><span class="pln">stringSize</span><span class="pun">/</span><span class="lit">2</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> buf</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span>