Overview

This project was designed to make an alarm clock that stops the alarm by matching a random color puzzle.

Final Project Product

Wires and other electrical parts inside the box

Powerline for the alarm clock

*For clear demonstration, I used a flat-plain type alarm clock video instead of a shoebox type.

Process images and review

Decision 1: Decide to test all components and check whether my idea will work.

During the prototype check day, I had a lot of problems with my gadgets. Therefore, I decided to test each gadget I brainstormed to see how it works and change if it does not work correctly.

Check 1: Turning off the alarm by changing the color of the led.

Here, there were two problems in total.

The first problem came up LCD becoming dull by having too many signals in a short amount of time. I solved this issue by adding a delay command on the Arduino.

The second problem came up with the neo-pixel strip. I tried to use the neo-pixel strip for this project but there were connection issues with the wire. Therefore, I decided to use a simpler RGB LED. (Unfortunately no photo)

Check 2: Learn how to use the other two new components

Fortunately, there were no big issues with testing these new modules.

Testing how the real-time clock module works

Adding Piezo Speaker to Arduino and tested with the Real-Time Clock module.

Adding all components into one circuit

Decision 2: For better design, I looked for a box where I can put components.

Decided to use a shoebox instead of just planting a bunch of circuits on top of the board

By this point, I thought the alarm clock will be a good design-wise but…

Final Product

the box was too big for a small alarm clock. D:

Discussion

I got the question, “[Is] there a function for accessibility for those who are color blind.” I never thought of this question before I build this device. For this project, there is no function that is accessible for color blinds. However, I can allow users to select a color pool when they set up the alarm. For example, if someone is green color blind, I build a push-button function that can exclude the green color type answer from the puzzle.  The second feedback I got was “you’re using a finite number of predefined colors, is there any reason to use a potentiometer as opposed to toggle switches?” In this case, yes. We can use the switch button to select those colors. However, I used a potentiometer because it gives more flexibility in the color pool. For instance, if I use a potentiometer I can use Violet(R:128 G:0 B:255) and Rose(R:255 G:0 B:128) for the color problem.

Overall, I was happy with my project function-wise. My project worked on how I intended. There were little mechanical wiring issues with LCDs but I was able to fix it after trying out several times. However, I was not satisfied with design-wise. In the beginning, I was thought using a shoebox would give a good and organized design aesthetic outfit because I saw other projects made with a shoebox. However, my LCD screen was too small compared to the size of the box creating an ugly shape.

During this project, I learned that sending too many signals in a short amount of time can create an error in Arduino. For example, as I mentioned in the process check 1 section, I had a problem with LCD being dull when I renewed the LCD screen every 1 millisecond. It did not create a problem when I used LCD only, but it generated dull letters when I turned my LCDs. I was able to solve this problem by adding a delay command on Arduino.

If I have a second chance to rebuild this project, I will add several new functions to my alarm clock. First, I want to add a push-button function so that I can modify the time without connecting the computer. Currently, I am resetting my time based on the computer and codes. So, if I need to change alarm time or clock time, I need to turn on the computer and re-upload code when I need to change those settings. Also, I want to customize the size of the box to improve aesthetic value.

 

Technical information

Schematic:

Code:

  1. <span class="com">/*
  2. * Alarm Clock with color puzzles
  3. * Daniel Moon (seonghym)
  4. *
  5. *
  6. * Description: This code takes the time from the computer and computes the time
  7. * on LCD screen by using the Real Time Clock Module. Then, if it reaches a certain time,
  8. * the speaker starts to ring. To turn off the speaker, we need to match the random color
  9. * specified on the LCD screen with LED attached to the circuit by turning three potentiometers.
  10. *
  11. *Credit:
  12. * -Real Time Clock Module
  13. * https://forum.arduino.cc/index.php?topic=128928.0
  14. *
  15. * -Sample Speaker Code in Arduino website
  16. * https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneMelody
  17. *
  18. * Pin mapping:
  19. *
  20. * pin | mode | description
  21. * ------|--------|------------
  22. 8 output Speaker
  23. 7 output LCD pin(B)
  24. 6 output LCD pin(G)
  25. 5 output LCD pin(R)
  26. A2 input Potentiometer for Red Color
  27. A3 input Potentiometer for Green Color
  28. A4 input Potentiometer for Blue Color
  29. 3 ouput LCD rs
  30. 4 output LCD enable
  31. 10 output LCD d4
  32. 11 output LCD d5
  33. 12 output LCD d6
  34. 13 output LCD d7
  35. */</span><span class="pln">
  36. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><LiquidCrystal.h></span><span class="pln">
  37. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><RTClib.h></span><span class="pln">
  38. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><Wire.h></span><span class="pln">
  39. RTC_DS1307 RTC</span><span class="pun">;</span><span class="pln">
  40. </span><span class="com">//LCD set</span><span class="pln">
  41. </span><span class="typ">LiquidCrystal</span><span class="pln"> lcd</span><span class="pun">(</span><span class="lit">3</span><span class="pun">,</span><span class="lit">4</span><span class="pun">,</span><span class="lit">10</span><span class="pun">,</span><span class="lit">11</span><span class="pun">,</span><span class="lit">12</span><span class="pun">,</span><span class="lit">13</span><span class="pun">);</span><span class="com">//LCD</span><span class="pln">
  42. </span><span class="com">//Sets pin for LED change</span><span class="pln">
  43. </span><span class="com">#define</span><span class="pln"> redPotPin A2
  44. </span><span class="com">#define</span><span class="pln"> bluePotPin A3
  45. </span><span class="com">#define</span><span class="pln"> greenPotPin A4
  46. </span><span class="com">//For timer counts</span><span class="pln">
  47. </span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> timeVal</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  48. </span><span class="com">//Sets alarm time</span><span class="pln">
  49. </span><span class="kwd">int</span><span class="pln"> alarmHour </span><span class="pun">=</span><span class="pln"> </span><span class="lit">22</span><span class="pun">;</span><span class="pln">
  50. </span><span class="kwd">int</span><span class="pln"> alarmminute </span><span class="pun">=</span><span class="pln"> </span><span class="lit">47</span><span class="pun">;</span><span class="pln">
  51. </span><span class="com">//Sets puzzle value</span><span class="pln">
  52. </span><span class="com">//Total 7 different color types.</span><span class="pln">
  53. </span><span class="typ">String</span><span class="pln"> colour</span><span class="pun">[]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="str">"white"</span><span class="pun">,</span><span class="str">"blue"</span><span class="pun">,</span><span class="str">"green"</span><span class="pun">,</span><span class="str">"red"</span><span class="pun">,</span><span class="str">"yellow"</span><span class="pun">,</span><span class="str">"purple"</span><span class="pun">,</span><span class="str">"cyan"</span><span class="pun">};</span><span class="pln">
  54. </span><span class="kwd">int</span><span class="pln"> randVal </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  55. </span><span class="com">//Sets pin numbers</span><span class="pln">
  56. </span><span class="kwd">int</span><span class="pln"> speakerPin</span><span class="pun">=</span><span class="lit">8</span><span class="pun">;</span><span class="pln">
  57. </span><span class="kwd">int</span><span class="pln"> redLedPin </span><span class="pun">=</span><span class="pln"> </span><span class="lit">5</span><span class="pun">;</span><span class="pln">
  58. </span><span class="kwd">int</span><span class="pln"> greenLedPin </span><span class="pun">=</span><span class="pln"> </span><span class="lit">6</span><span class="pun">;</span><span class="pln">
  59. </span><span class="kwd">int</span><span class="pln"> blueLedPin </span><span class="pun">=</span><span class="pln"> </span><span class="lit">7</span><span class="pun">;</span><span class="pln">
  60. </span><span class="com">//Sets Color of LED</span><span class="pln">
  61. </span><span class="kwd">int</span><span class="pln"> color_value</span><span class="pun">[</span><span class="lit">3</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">};</span><span class="pln">
  62. </span><span class="kwd">int</span><span class="pln"> target_color_value</span><span class="pun">[</span><span class="lit">3</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="lit">1</span><span class="pun">,</span><span class="lit">1</span><span class="pun">,</span><span class="lit">1</span><span class="pun">};</span><span class="pln">
  63. </span><span class="com">//Check whether day passed</span><span class="pln">
  64. </span><span class="kwd">bool</span><span class="pln"> timePassed </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
  65. </span><span class="com">//Check whether alarm clock is ringing</span><span class="pln">
  66. boolwakeVal </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  67. </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">
  68. randomSeed</span><span class="pun">(</span><span class="pln">analogRead</span><span class="pun">(</span><span class="lit">0</span><span class="pun">));</span><span class="pln">
  69. </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">
  70. </span><span class="com">//Adjust Real Time Clock with PC</span><span class="pln">
  71. </span><span class="typ">Wire</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">();</span><span class="pln">
  72. RTC</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">();</span><span class="pln">
  73. RTC</span><span class="pun">.</span><span class="pln">adjust</span><span class="pun">(</span><span class="typ">DateTime</span><span class="pun">(</span><span class="pln">__DATE__</span><span class="pun">,</span><span class="pln">__TIME__</span><span class="pun">));</span><span class="pln">
  74. </span><span class="com">//Adjust LCD</span><span class="pln">
  75. lcd</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">(</span><span class="lit">16</span><span class="pun">,</span><span class="lit">2</span><span class="pun">);</span><span class="pln">
  76. lcd</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">
  77. </span><span class="com">//sets a random value for puzzle</span><span class="pln">
  78. randVal </span><span class="pun">=</span><span class="pln"> random</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">);</span><span class="pln">
  79. </span><span class="com">//Serial.println(randVal);</span><span class="pln">
  80. </span><span class="com">//Sets outputs for RGB LED</span><span class="pln">
  81. pinMode</span><span class="pun">(</span><span class="pln">redLedPin</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  82. pinMode</span><span class="pun">(</span><span class="pln">greenLedPin</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  83. pinMode</span><span class="pun">(</span><span class="pln">blueLedPin</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  84. </span><span class="pun">}</span><span class="pln">
  85. </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">
  86. </span><span class="typ">DateTime</span><span class="pln"> now</span><span class="pun">=</span><span class="pln">RTC</span><span class="pun">.</span><span class="pln">now</span><span class="pun">();</span><span class="pln">
  87. </span><span class="com">//only executes every 1 seconds</span><span class="pln">
  88. </span><span class="kwd">if</span><span class="pun">(</span><span class="pln">millis</span><span class="pun">()-</span><span class="pln">timeVal</span><span class="pun">>=</span><span class="lit">1000</span><span class="pun">){</span><span class="pln">
  89. </span><span class="com">//Sets LCD with correct time</span><span class="pln">
  90. lcd</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">
  91. lcd</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">0</span><span class="pun">);</span><span class="pln">
  92. lcd</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">now</span><span class="pun">.</span><span class="pln">month</span><span class="pun">()</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> </span><span class="str">"/"</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> now</span><span class="pun">.</span><span class="pln">day</span><span class="pun">()+</span><span class="pln"> </span><span class="str">" "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> now</span><span class="pun">.</span><span class="pln">hour</span><span class="pun">()+</span><span class="str">":"</span><span class="pun">+</span><span class="pln">now</span><span class="pun">.</span><span class="pln">minute</span><span class="pun">()+</span><span class="str">":"</span><span class="pun">+</span><span class="pln">now</span><span class="pun">.</span><span class="pln">second</span><span class="pun">());</span><span class="pln">
  93. </span><span class="kwd">if</span><span class="pun">(</span><span class="pln">wakeVal</span><span class="pun">){</span><span class="pln">
  94. </span><span class="com">//Operates the color puzzle</span><span class="pln">
  95. lcd</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">
  96. lcd</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="pln">colour</span><span class="pun">[</span><span class="pln">randVal</span><span class="pun">]);</span><span class="pln">
  97. </span><span class="pun">}</span><span class="pln">
  98. timeVal</span><span class="pun">=</span><span class="pln">millis</span><span class="pun">();</span><span class="pln">
  99. </span><span class="pun">}</span><span class="pln">
  100. </span><span class="kwd">if</span><span class="pun">(</span><span class="pln">now</span><span class="pun">.</span><span class="pln">hour</span><span class="pun">()</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> </span><span class="lit">24</span><span class="pun">){</span><span class="pln">
  101. </span><span class="com">//Resets the alarm activation</span><span class="pln">
  102. timePassed </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
  103. </span><span class="pun">}</span><span class="pln">
  104. </span><span class="kwd">if</span><span class="pun">((</span><span class="pln">wakeVal </span><span class="pun">||</span><span class="pln"> now</span><span class="pun">.</span><span class="pln">hour</span><span class="pun">()</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> alarmHour </span><span class="pun">&&</span><span class="pln"> now</span><span class="pun">.</span><span class="pln">minute</span><span class="pun">()</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> alarmminute</span><span class="pun">)</span><span class="pln"> </span><span class="pun">&&</span><span class="pln"> timePassed</span><span class="pun">){</span><span class="pln">
  105. wakeVal </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
  106. </span><span class="com">//Serial.println("Made it 1");</span><span class="pln">
  107. </span><span class="com">//Rings the alarm</span><span class="pln">
  108. tone</span><span class="pun">(</span><span class="pln">speakerPin</span><span class="pun">,</span><span class="pln"> </span><span class="lit">262</span><span class="pun">,</span><span class="pln"> </span><span class="lit">250</span><span class="pun">);</span><span class="pln">
  109. </span><span class="com">//Sets the puzzle</span><span class="pln">
  110. </span><span class="typ">ColortoNum</span><span class="pun">(</span><span class="pln">colour</span><span class="pun">[</span><span class="pln">randVal</span><span class="pun">]);</span><span class="pln">
  111. </span><span class="com">//Changes LED color</span><span class="pln">
  112. color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">redPotPin</span><span class="pun">)/</span><span class="lit">4</span><span class="pun">;</span><span class="pln"> </span><span class="com">//(0~1023 => 1024/4=256)</span><span class="pln">
  113. color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">bluePotPin</span><span class="pun">)/</span><span class="lit">4</span><span class="pun">;</span><span class="pln">
  114. color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">greenPotPin</span><span class="pun">)/</span><span class="lit">4</span><span class="pun">;</span><span class="pln">
  115. </span><span class="typ">ColorVal</span><span class="pun">(</span><span class="pln">color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">],</span><span class="pln">color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">],</span><span class="pln">color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]);</span><span class="pln">
  116. </span><span class="pun">}</span><span class="pln">
  117. </span><span class="com">//Chekc whether the puzzle is correct</span><span class="pln">
  118. </span><span class="kwd">if</span><span class="pun">(</span><span class="pln">timePassed </span><span class="pun">&&</span><span class="pln"> color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]&&</span><span class="pln">color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]&&</span><span class="pln">color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]){</span><span class="pln">
  119. </span><span class="kwd">if</span><span class="pun">(</span><span class="pln">wakeVal</span><span class="pun">){</span><span class="pln">
  120. timePassed </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  121. </span><span class="pun">}</span><span class="pln">
  122. </span><span class="com">//Turns the puzzle and alarm off</span><span class="pln">
  123. wakeVal </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  124. randVal </span><span class="pun">=</span><span class="pln"> random</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">);</span><span class="pln">
  125. </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">randVal</span><span class="pun">);</span><span class="pln">
  126. </span><span class="com">//ColortoNum(colour[randVal]);</span><span class="pln">
  127. </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Made it 2"</span><span class="pun">);</span><span class="pln">
  128. noTone</span><span class="pun">(</span><span class="pln">speakerPin</span><span class="pun">);</span><span class="pln">
  129. </span><span class="typ">ColorVal</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  130. </span><span class="pun">}</span><span class="pln">
  131. </span><span class="pun">}</span><span class="pln">
  132. </span><span class="com">//Sets LED color</span><span class="pln">
  133. </span><span class="kwd">void</span><span class="pln"> </span><span class="typ">ColorVal</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> red</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> green</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> blue</span><span class="pun">)</span><span class="pln">
  134. </span><span class="pun">{</span><span class="pln">
  135. analogWrite</span><span class="pun">(</span><span class="pln">redLedPin</span><span class="pun">,</span><span class="pln"> red</span><span class="pun">);</span><span class="pln">
  136. analogWrite</span><span class="pun">(</span><span class="pln">greenLedPin</span><span class="pun">,</span><span class="pln"> green</span><span class="pun">);</span><span class="pln">
  137. analogWrite</span><span class="pun">(</span><span class="pln">blueLedPin</span><span class="pun">,</span><span class="pln"> blue</span><span class="pun">);</span><span class="pln">
  138. </span><span class="pun">}</span><span class="pln">
  139. </span><span class="com">//Check Whether LED shows correct color</span><span class="pln">
  140. </span><span class="kwd">void</span><span class="pln"> </span><span class="typ">ColortoNum</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> colour</span><span class="pun">){</span><span class="pln">
  141. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">colour </span><span class="pun">==</span><span class="pln"> </span><span class="str">"white"</span><span class="pun">){</span><span class="pln">
  142. target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
  143. target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
  144. target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
  145. </span><span class="pun">}</span><span class="pln">
  146. </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">colour </span><span class="pun">==</span><span class="pln"> </span><span class="str">"blue"</span><span class="pun">){</span><span class="pln">
  147. target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  148. target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  149. target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
  150. </span><span class="pun">}</span><span class="pln">
  151. </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">colour </span><span class="pun">==</span><span class="pln"> </span><span class="str">"red"</span><span class="pun">){</span><span class="pln">
  152. target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
  153. target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  154. target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  155. </span><span class="pun">}</span><span class="pln">
  156. </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">colour </span><span class="pun">==</span><span class="pln"> </span><span class="str">"green"</span><span class="pun">){</span><span class="pln">
  157. target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  158. target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
  159. target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  160. </span><span class="pun">}</span><span class="pln">
  161. </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">colour </span><span class="pun">==</span><span class="pln"> </span><span class="str">"yellow"</span><span class="pun">){</span><span class="pln">
  162. target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
  163. target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
  164. target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  165. </span><span class="pun">}</span><span class="pln">
  166. </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">colour </span><span class="pun">==</span><span class="pln"> </span><span class="str">"purple"</span><span class="pun">){</span><span class="pln">
  167. target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
  168. target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  169. target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
  170. </span><span class="pun">}</span><span class="pln">
  171. </span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">colour </span><span class="pun">==</span><span class="pln"> </span><span class="str">"cyan"</span><span class="pun">){</span><span class="pln">
  172. target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
  173. target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
  174. target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
  175. </span><span class="pun">}</span><span class="pln">
  176. </span><span class="pun">}</span>
<span class="com">/*
* Alarm Clock with color puzzles
* Daniel Moon (seonghym)
*
*
* Description: This code takes the time from the computer and computes the time
* on LCD screen by using the Real Time Clock Module. Then, if it reaches a certain time,
* the speaker starts to ring. To turn off the speaker, we need to match the random color
* specified on the LCD screen with LED attached to the circuit by turning three potentiometers.
*
*Credit: 
*   -Real Time Clock Module
*   https://forum.arduino.cc/index.php?topic=128928.0
*   
*   -Sample Speaker Code in Arduino website
*   https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneMelody
*
* Pin mapping:
*
* pin   | mode   | description
* ------|--------|------------
  8      output   Speaker
  7      output   LCD pin(B)
  6      output   LCD pin(G)
  5      output   LCD pin(R)
  A2     input    Potentiometer for Red Color
  A3     input    Potentiometer for Green Color
  A4     input    Potentiometer for Blue Color
  3      ouput    LCD rs
  4      output   LCD enable
  10     output   LCD d4
  11     output   LCD d5
  12     output   LCD d6
  13     output   LCD d7
*/</span><span class="pln">

</span><span class="com">#include</span><span class="pln"> </span><span class="str"><LiquidCrystal.h></span><span class="pln">
</span><span class="com">#include</span><span class="pln"> </span><span class="str"><RTClib.h></span><span class="pln">
</span><span class="com">#include</span><span class="pln"> </span><span class="str"><Wire.h></span><span class="pln">
RTC_DS1307 RTC</span><span class="pun">;</span><span class="pln">

</span><span class="com">//LCD set</span><span class="pln">
</span><span class="typ">LiquidCrystal</span><span class="pln"> lcd</span><span class="pun">(</span><span class="lit">3</span><span class="pun">,</span><span class="lit">4</span><span class="pun">,</span><span class="lit">10</span><span class="pun">,</span><span class="lit">11</span><span class="pun">,</span><span class="lit">12</span><span class="pun">,</span><span class="lit">13</span><span class="pun">);</span><span class="com">//LCD</span><span class="pln">

</span><span class="com">//Sets pin for LED change</span><span class="pln">
</span><span class="com">#define</span><span class="pln"> redPotPin A2
</span><span class="com">#define</span><span class="pln"> bluePotPin A3
</span><span class="com">#define</span><span class="pln"> greenPotPin A4

</span><span class="com">//For timer counts</span><span class="pln">
</span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> timeVal</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln">

</span><span class="com">//Sets alarm time</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> alarmHour </span><span class="pun">=</span><span class="pln"> </span><span class="lit">22</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> alarmminute </span><span class="pun">=</span><span class="pln"> </span><span class="lit">47</span><span class="pun">;</span><span class="pln">

</span><span class="com">//Sets puzzle value</span><span class="pln">
</span><span class="com">//Total 7 different color types.</span><span class="pln">
</span><span class="typ">String</span><span class="pln"> colour</span><span class="pun">[]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="str">"white"</span><span class="pun">,</span><span class="str">"blue"</span><span class="pun">,</span><span class="str">"green"</span><span class="pun">,</span><span class="str">"red"</span><span class="pun">,</span><span class="str">"yellow"</span><span class="pun">,</span><span class="str">"purple"</span><span class="pun">,</span><span class="str">"cyan"</span><span class="pun">};</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> randVal </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">//Sets pin numbers</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> speakerPin</span><span class="pun">=</span><span class="lit">8</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> redLedPin </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">int</span><span class="pln"> greenLedPin </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"> blueLedPin </span><span class="pun">=</span><span class="pln"> </span><span class="lit">7</span><span class="pun">;</span><span class="pln">

</span><span class="com">//Sets Color of LED</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> color_value</span><span class="pun">[</span><span class="lit">3</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">};</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> target_color_value</span><span class="pun">[</span><span class="lit">3</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="lit">1</span><span class="pun">,</span><span class="lit">1</span><span class="pun">,</span><span class="lit">1</span><span class="pun">};</span><span class="pln">

</span><span class="com">//Check whether day passed</span><span class="pln">
</span><span class="kwd">bool</span><span class="pln"> timePassed </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
</span><span class="com">//Check whether alarm clock is ringing</span><span class="pln">
boolwakeVal </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">void</span><span class="pln"> setup</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
randomSeed</span><span class="pun">(</span><span class="pln">analogRead</span><span class="pun">(</span><span class="lit">0</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">  

</span><span class="com">//Adjust Real Time Clock with PC</span><span class="pln">
</span><span class="typ">Wire</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="kwd">begin</span><span class="pun">();</span><span class="pln">
RTC</span><span class="pun">.</span><span class="pln">adjust</span><span class="pun">(</span><span class="typ">DateTime</span><span class="pun">(</span><span class="pln">__DATE__</span><span class="pun">,</span><span class="pln">__TIME__</span><span class="pun">));</span><span class="pln">
</span><span class="com">//Adjust LCD</span><span class="pln">
lcd</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">(</span><span class="lit">16</span><span class="pun">,</span><span class="lit">2</span><span class="pun">);</span><span class="pln">
lcd</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">

</span><span class="com">//sets a random value for puzzle</span><span class="pln">
randVal </span><span class="pun">=</span><span class="pln"> random</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">);</span><span class="pln">
</span><span class="com">//Serial.println(randVal);</span><span class="pln">

</span><span class="com">//Sets outputs for RGB LED</span><span class="pln">
 pinMode</span><span class="pun">(</span><span class="pln">redLedPin</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">greenLedPin</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">blueLedPin</span><span class="pun">,</span><span class="pln"> OUTPUT</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="typ">DateTime</span><span class="pln"> now</span><span class="pun">=</span><span class="pln">RTC</span><span class="pun">.</span><span class="pln">now</span><span class="pun">();</span><span class="pln">
</span><span class="com">//only executes every 1 seconds</span><span class="pln">
</span><span class="kwd">if</span><span class="pun">(</span><span class="pln">millis</span><span class="pun">()-</span><span class="pln">timeVal</span><span class="pun">>=</span><span class="lit">1000</span><span class="pun">){</span><span class="pln">
  </span><span class="com">//Sets LCD with correct time</span><span class="pln">
  lcd</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">();</span><span class="pln">
  lcd</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">0</span><span class="pun">);</span><span class="pln">
  lcd</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">now</span><span class="pun">.</span><span class="pln">month</span><span class="pun">()</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> </span><span class="str">"/"</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> now</span><span class="pun">.</span><span class="pln">day</span><span class="pun">()+</span><span class="pln"> </span><span class="str">" "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> now</span><span class="pun">.</span><span class="pln">hour</span><span class="pun">()+</span><span class="str">":"</span><span class="pun">+</span><span class="pln">now</span><span class="pun">.</span><span class="pln">minute</span><span class="pun">()+</span><span class="str">":"</span><span class="pun">+</span><span class="pln">now</span><span class="pun">.</span><span class="pln">second</span><span class="pun">());</span><span class="pln">
  </span><span class="kwd">if</span><span class="pun">(</span><span class="pln">wakeVal</span><span class="pun">){</span><span class="pln">
    </span><span class="com">//Operates the color puzzle</span><span class="pln">
    lcd</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">
    lcd</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="pln">colour</span><span class="pun">[</span><span class="pln">randVal</span><span class="pun">]);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
  timeVal</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">
</span><span class="kwd">if</span><span class="pun">(</span><span class="pln">now</span><span class="pun">.</span><span class="pln">hour</span><span class="pun">()</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> </span><span class="lit">24</span><span class="pun">){</span><span class="pln">
  </span><span class="com">//Resets the alarm activation</span><span class="pln">
  timePassed </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="pun">((</span><span class="pln">wakeVal </span><span class="pun">||</span><span class="pln"> now</span><span class="pun">.</span><span class="pln">hour</span><span class="pun">()</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> alarmHour </span><span class="pun">&&</span><span class="pln"> now</span><span class="pun">.</span><span class="pln">minute</span><span class="pun">()</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> alarmminute</span><span class="pun">)</span><span class="pln"> </span><span class="pun">&&</span><span class="pln"> timePassed</span><span class="pun">){</span><span class="pln">
  wakeVal </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
  </span><span class="com">//Serial.println("Made it 1");</span><span class="pln">
  </span><span class="com">//Rings the alarm</span><span class="pln">
  tone</span><span class="pun">(</span><span class="pln">speakerPin</span><span class="pun">,</span><span class="pln"> </span><span class="lit">262</span><span class="pun">,</span><span class="pln"> </span><span class="lit">250</span><span class="pun">);</span><span class="pln">
  </span><span class="com">//Sets the puzzle</span><span class="pln">
  </span><span class="typ">ColortoNum</span><span class="pun">(</span><span class="pln">colour</span><span class="pun">[</span><span class="pln">randVal</span><span class="pun">]);</span><span class="pln">
  </span><span class="com">//Changes LED color</span><span class="pln">
  color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">redPotPin</span><span class="pun">)/</span><span class="lit">4</span><span class="pun">;</span><span class="pln"> </span><span class="com">//(0~1023 => 1024/4=256)</span><span class="pln">
  color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">bluePotPin</span><span class="pun">)/</span><span class="lit">4</span><span class="pun">;</span><span class="pln">
  color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">greenPotPin</span><span class="pun">)/</span><span class="lit">4</span><span class="pun">;</span><span class="pln">
  </span><span class="typ">ColorVal</span><span class="pun">(</span><span class="pln">color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">],</span><span class="pln">color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">],</span><span class="pln">color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="com">//Chekc whether the puzzle is correct</span><span class="pln">
</span><span class="kwd">if</span><span class="pun">(</span><span class="pln">timePassed </span><span class="pun">&&</span><span class="pln"> color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]&&</span><span class="pln">color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]&&</span><span class="pln">color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]){</span><span class="pln">
  </span><span class="kwd">if</span><span class="pun">(</span><span class="pln">wakeVal</span><span class="pun">){</span><span class="pln">
    timePassed </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">//Turns the puzzle and alarm off</span><span class="pln">
  wakeVal </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
  randVal </span><span class="pun">=</span><span class="pln"> random</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</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">randVal</span><span class="pun">);</span><span class="pln">
  </span><span class="com">//ColortoNum(colour[randVal]);</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="str">"Made it 2"</span><span class="pun">);</span><span class="pln">
  noTone</span><span class="pun">(</span><span class="pln">speakerPin</span><span class="pun">);</span><span class="pln">
  </span><span class="typ">ColorVal</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</span><span class="pun">,</span><span class="lit">0</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">//Sets LED color</span><span class="pln">
</span><span class="kwd">void</span><span class="pln"> </span><span class="typ">ColorVal</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> red</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> green</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> blue</span><span class="pun">)</span><span class="pln">
</span><span class="pun">{</span><span class="pln">
  analogWrite</span><span class="pun">(</span><span class="pln">redLedPin</span><span class="pun">,</span><span class="pln"> red</span><span class="pun">);</span><span class="pln">
  analogWrite</span><span class="pun">(</span><span class="pln">greenLedPin</span><span class="pun">,</span><span class="pln"> green</span><span class="pun">);</span><span class="pln">
  analogWrite</span><span class="pun">(</span><span class="pln">blueLedPin</span><span class="pun">,</span><span class="pln"> blue</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">

</span><span class="com">//Check Whether LED shows correct color</span><span class="pln">
</span><span class="kwd">void</span><span class="pln"> </span><span class="typ">ColortoNum</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> colour</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">colour </span><span class="pun">==</span><span class="pln"> </span><span class="str">"white"</span><span class="pun">){</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</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="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">colour </span><span class="pun">==</span><span class="pln"> </span><span class="str">"blue"</span><span class="pun">){</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</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="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">colour </span><span class="pun">==</span><span class="pln"> </span><span class="str">"red"</span><span class="pun">){</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</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="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">colour </span><span class="pun">==</span><span class="pln"> </span><span class="str">"green"</span><span class="pun">){</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</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="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">colour </span><span class="pun">==</span><span class="pln"> </span><span class="str">"yellow"</span><span class="pun">){</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</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="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">colour </span><span class="pun">==</span><span class="pln"> </span><span class="str">"purple"</span><span class="pun">){</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</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="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">colour </span><span class="pun">==</span><span class="pln"> </span><span class="str">"cyan"</span><span class="pun">){</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
    target_color_value</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">255</span><span class="pun">;</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span>