Advertisement
Guest User

Color Clock

a guest
Dec 9th, 2014
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 KB | None | 0 0
  1. // Date and time functions using a DS1307 RTC connected via I2C and Wire lib
  2. #include <Wire.h>
  3. #include <SPI.h> // not used here, but needed to prevent a RTClib compile error
  4. #include <RTClib.h>
  5. #include <Adafruit_NeoPixel.h>
  6.  
  7. #define PIN 6
  8.  
  9. Adafruit_NeoPixel stripHour = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);
  10. RTC_DS3231 RTC;
  11. long mHour;
  12.  
  13. void setup () {
  14.  
  15. stripHour.begin();
  16. stripHour.show(); // Initialize all pixels to 'off'
  17.  
  18. Serial.begin(57600);
  19. Wire.begin();
  20. RTC.begin();
  21.  
  22. if (! RTC.isrunning()) {
  23. Serial.println("RTC is NOT running!");
  24. // following line sets the RTC to the date & time this sketch was compiled
  25. RTC.adjust(DateTime(__DATE__, __TIME__));
  26.  
  27.  
  28. }
  29. }
  30.  
  31. /******************************
  32. Main Loop
  33. *******************************/
  34. void loop() {
  35.  
  36. DateTime now = RTC.now();
  37.  
  38. //Prints time
  39. Serial.print(now.hour(), DEC);
  40. Serial.print(':');
  41. Serial.print(now.minute(), DEC);
  42. Serial.print(':');
  43. Serial.print(now.second(), DEC);
  44. Serial.println();
  45.  
  46. Serial.println();
  47. delay(1000);
  48.  
  49. mHour = now.hour();// defining hour now
  50. long mn = now.minute();
  51.  
  52. //Controlling the hour
  53. if (mHour == 0){
  54. hour_0();
  55. }
  56. if(mHour == 1){
  57. hour_1();
  58. }
  59. if(mHour == 2){
  60. hour_2();
  61. }
  62. if(mHour == 3){
  63. hour_3();
  64. }
  65. if(mHour == 4){
  66. hour_4();
  67. }
  68. if(mHour == 5){
  69. hour_5();
  70. }
  71. if(mHour == 6){
  72. hour_6();
  73. }
  74. if(mHour == 7){
  75. hour_7();
  76. }
  77. if(mHour == 8){
  78. hour_8();
  79. }
  80. if(mHour == 9){
  81. hour_9();
  82. }
  83. if(mHour == 10){
  84. hour_10();
  85. }
  86. if(mHour == 11){
  87. hour_11();
  88. }
  89. if(mHour == 12){
  90. hour_12();
  91. }
  92. if(mHour == 13){
  93. hour_13;
  94. }
  95. if(mHour == 14){
  96. hour_14();
  97. }
  98. if(mHour == 15){
  99. hour_15();
  100. }
  101. if(mHour == 16){
  102. hour_16();
  103. }
  104. if(mHour == 17){
  105. hour_17();
  106. }
  107. if(mHour == 18){
  108. hour_18();
  109. }
  110. if(mHour == 19){
  111. hour_19();
  112. }
  113. if(mHour == 20){
  114. hour_20();
  115. }
  116. if(mHour == 21){
  117. hour_21();
  118. }
  119. if(mHour == 22){
  120. hour_22();
  121. }
  122. if (mHour == 23){
  123. hour_23();
  124. }
  125. }
  126.  
  127. /******************************
  128. Fade
  129. *******************************/
  130. void fade(){
  131. }
  132.  
  133. /******************************
  134. Color Wipe
  135. *******************************/
  136. //Fills Neopixil
  137. void colorWipe(uint32_t c, uint8_t wait) {
  138. for(uint16_t i=0; i<stripHour.numPixels(); i++) {
  139. stripHour.setPixelColor(i, c);
  140. stripHour.show();
  141. delay(wait);
  142. }
  143. }
  144.  
  145. /******************************
  146. Set Color
  147. *******************************/
  148. // functions for the colors of each hour
  149. void hour_0(){
  150. colorWipe(stripHour.Color(25, 25, 112), 50); //Darker Blue
  151. }
  152.  
  153. void hour_1(){
  154. colorWipe(stripHour.Color(136, 206, 250), 50); //Sky Blue
  155. }
  156.  
  157. void hour_2(){
  158. colorWipe(stripHour.Color(175, 238, 238), 50); //Light Blue
  159. }
  160.  
  161. void hour_3(){
  162. colorWipe(stripHour.Color(221, 160, 221), 50); //Pink
  163. }
  164.  
  165. void hour_4(){
  166. colorWipe(stripHour.Color(123, 104, 238), 50); //Purple
  167. }
  168.  
  169. void hour_5(){
  170. colorWipe(stripHour.Color(75, 0, 130), 50); //Violet
  171. }
  172.  
  173. void hour_6(){
  174. colorWipe(stripHour.Color(153, 50, 204), 50); //Light Purple
  175. }
  176.  
  177. void hour_7(){
  178. colorWipe(stripHour.Color(238, 130, 238), 50); //Light Pink
  179. }
  180.  
  181. void hour_8(){
  182. colorWipe(stripHour.Color(255, 215, 0), 50); //Light Oragne
  183. }
  184.  
  185. void hour_9(){
  186. colorWipe(stripHour.Color(255, 140, 0), 50); //Orange
  187. }
  188.  
  189. void hour_10(){
  190. colorWipe(stripHour.Color(160, 80, 0), 50); // Light Red
  191. }
  192.  
  193. void hour_11(){
  194. colorWipe(stripHour.Color(255, 0, 0), 50); //Red
  195. }
  196.  
  197. void hour_12(){
  198. colorWipe(stripHour.Color(178, 34, 34), 50); //Dark Red
  199. }
  200.  
  201. void hour_13(){
  202. colorWipe(stripHour.Color(210, 105, 30), 50); //Red Orange
  203. }
  204.  
  205. void hour_14(){
  206. colorWipe(stripHour.Color(245, 222, 179), 50); //Light Brown
  207. }
  208.  
  209. void hour_15(){
  210. colorWipe(stripHour.Color(173, 255, 47), 50); //Bright Green
  211. }
  212.  
  213. void hour_16(){
  214. colorWipe(stripHour.Color(0, 255, 154), 50); //Bright Yellow Green
  215. }
  216.  
  217. void hour_17(){
  218. colorWipe(stripHour.Color(154, 205, 50), 50); //Light Green
  219. }
  220.  
  221. void hour_18(){
  222. colorWipe(stripHour.Color(0, 255, 0), 50); //Green
  223. }
  224.  
  225. void hour_19(){
  226. colorWipe(stripHour.Color(0, 100, 0), 50); //Dark Green
  227. }
  228.  
  229. void hour_20(){
  230. colorWipe(stripHour.Color(0, 0, 139), 50); //Navy Blue
  231. }
  232.  
  233. void hour_21(){
  234. colorWipe(stripHour.Color(119, 136, 153), 50); //Blue Grey
  235. }
  236.  
  237. void hour_22(){
  238. colorWipe(stripHour.Color(25, 25, 112), 50); //Violet Blue
  239. }
  240.  
  241. void hour_23(){
  242. colorWipe(stripHour.Color(0, 0, 255), 50); //Blue
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement