Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.87 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #include <RTClib.h>
  3. #include <Wire.h>
  4.  
  5. RTC_DS3231 rtc;
  6.  
  7. #define PIN 10
  8. #define NUM_LEDS 14
  9. #define BRIGHTNESS 60
  10.  
  11. long mHour;
  12. long mMinute;
  13.  
  14. Adafruit_NeoPixel stripHour = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800);
  15. Adafruit_NeoPixel stripMin = Adafruit_NeoPixel(20, 9, NEO_GRBW + NEO_KHZ800);
  16.  
  17. int colorSet;
  18.  
  19. void setup() {
  20.   delay(3000); //power-up safety delay
  21.   stripHour.setBrightness(BRIGHTNESS);
  22.   stripHour.begin();
  23.   stripHour.show();
  24.   stripMin.setBrightness(BRIGHTNESS);
  25.   stripMin.begin();
  26.   stripMin.show();
  27.    
  28.  // Serial.begin(57600);
  29.    if (! rtc.begin()) {
  30.     Serial.println("Couldn't find RTC");
  31.     while (1);
  32.   }
  33.     //sets date and time
  34.     rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  35. }
  36.  
  37. void loop() {
  38.   DateTime now = rtc.now();
  39.  
  40.   //Prints Time
  41.   Serial.print(now.hour(), DEC);
  42.   Serial.print(':');
  43.   Serial.print(now.minute(), DEC);
  44.   Serial.print(':');
  45.   Serial.print(now.second(), DEC);
  46.   Serial.println();
  47.  
  48.   delay(1000);
  49.  
  50.   //Controlling the hour and minute
  51.   mHour = now.hour();
  52.   mMinute = now.minute();
  53.  
  54.   if (mHour == 0) {
  55.      breathe(stripHour.Color(25, 25, 112), 60);//Darker Blue
  56.      Serial.print("Hello");
  57. }
  58.   if (mHour == 1) {
  59.      breathe(stripHour.Color(136, 206, 250), 60);//Sky Blue
  60. }
  61.   if (mHour == 2) {
  62.      minColor();
  63.      //whiteOverRainbow(20,75,5);
  64.      breathe(stripHour.Color(175, 238, 238), 60);//Light blue
  65.      Serial.print("Hello");
  66.  }
  67.    if (mHour == 3) {
  68.      breathe(stripHour.Color(221, 160, 221), 60);//Pink
  69. }
  70.   if (mHour == 4) {
  71.      breathe(stripHour.Color(123, 104, 238), 60);//Purple
  72. }
  73.   if (mHour == 5) {
  74.      breathe(stripHour.Color(75, 0, 130), 60);//Violet
  75. }
  76.   if (mHour == 6) {
  77.      breathe(stripHour.Color(153, 50, 204), 60);//Light Purple
  78. }
  79.   if (mHour == 7) {
  80.      breathe(stripHour.Color(238, 130, 238), 60);//Light Pink
  81. }
  82.   if (mHour == 8) {
  83.      breathe(stripHour.Color(255, 215, 0), 60);//Light Orange
  84. }
  85.   if (mHour == 9) {
  86.      breathe(stripHour.Color(255, 140, 0), 60);//Orange
  87. }
  88.   if (mHour == 10) {
  89.      breathe(stripHour.Color(160, 80, 0), 60);// Light Red
  90. }
  91.   if (mHour == 11) {
  92.      breathe(stripHour.Color(255, 0, 0), 60);//Red
  93. }
  94.   if (mHour == 12) {
  95.      breathe(stripHour.Color(178, 34, 34), 60);//Dark Red
  96. }
  97.   if (mHour == 13) {
  98.      breathe(stripHour.Color(210, 105, 30), 60);//Red Orange
  99. }
  100.   if (mHour == 14) {
  101.      breathe(stripHour.Color(245, 222, 179), 60);//Light Brown
  102. }
  103.   if (mHour == 15) {
  104.      breathe(stripHour.Color(173, 255, 47), 60);//Bright Green
  105. }
  106.   if (mHour == 16) {
  107.      breathe(stripHour.Color(0, 255, 154), 60);// Bright Yellow Green
  108. }
  109.   if (mHour == 17) {
  110.      breathe(stripHour.Color(154, 205, 50), 60);//Light Green
  111. }
  112.   if (mHour == 18) {
  113.      breathe(stripHour.Color(0, 255, 0), 60);//Green
  114. }
  115.   if (mHour == 19) {
  116.      breathe(stripHour.Color(0, 100, 0), 60);//Dark Green
  117. }
  118.   if (mHour == 20) {
  119.      breathe(stripHour.Color(0, 0, 139), 60);//Navy Blue
  120. }
  121.   if (mHour == 21) {
  122.      breathe(stripHour.Color(119, 136, 153), 60);// Blue Grey
  123. }
  124.   if (mHour == 22) {
  125.      breathe(stripHour.Color(25, 25, 112), 60);//Violet Blue
  126. }
  127.   if (mHour == 23) {
  128.      breathe(stripHour.Color(0, 0, 255), 60);//Blue
  129. }
  130. }
  131.  
  132. void breathe(uint32_t c, uint8_t wait) {
  133.   // Make the lights breathe
  134.   for (int i = 0; i < 1200; i++) {
  135.     // Intensity will go from 10 - MaximumBrightness in a "breathing" manner
  136.     float intensity = 100 /2.0 * (1.0 + sin(0.008 * i));
  137.     stripHour.setBrightness(intensity);
  138.     // Now set every LED to that color
  139.     for(uint16_t i=0; i<stripHour.numPixels(); i++) {
  140.     stripHour.setPixelColor(i, c);
  141.     }
  142.     Serial.println("loop here");
  143.     stripHour.show();
  144.     //Wait a bit before continuing to breathe
  145.     delay(5);  
  146.     }
  147.     Serial.println("did it make it");
  148. }
  149.  
  150. // Fill the dots one after the other with a color
  151. void colorWipe(uint32_t c, uint8_t wait) {
  152.   for(uint16_t i=0; i<stripHour.numPixels(); i++) {
  153.     stripHour.setPixelColor(i, c);
  154.     stripHour.show();
  155.     delay(wait);
  156.   }
  157. }
  158.  
  159. void fadeColor() {
  160.   for (int i=50; i <200; i++) {
  161.     stripHour.setBrightness(i);
  162.     stripHour.show();
  163.     delay(1);
  164.   }
  165.   for (int i=200; i>50; i++) {
  166.     stripHour.setBrightness(i);
  167.   }
  168. }
  169.  
  170. void minColor() {
  171.   DateTime now = rtc.now();
  172.   mMinute = now.minute();
  173.  
  174.   if (mMinute == 30){
  175.     Twinkle(0xff, 0, 0, 10, 100, false);
  176.     Serial.println("minute twinkle");
  177.   }
  178.   else {
  179.     breathe(stripMin.Color(0, 255, 0), 60);
  180.     Serial.println("minute breathe");
  181.   }
  182. }
  183.  
  184. void Twinkle(byte red, byte green, byte blue, int Count, int SpeedDelay, boolean OnlyOne) {
  185.   stripHour.Color(0,0,0);
  186.  
  187.   for (int i=0; i<Count; i++) {
  188.      stripHour.setPixelColor(random(NUM_LEDS),red,green,blue);
  189.      stripHour.show();
  190.      delay(SpeedDelay);
  191.      if(OnlyOne) {
  192.      stripHour.Color(0,0,0);
  193.      }
  194.    }
  195.  
  196.   delay(SpeedDelay);
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement