//**************************************** //* Hard Drive Neopixel Clock * //* John Guarnero 12/19/2015 * //**************************************** // include the library code: #include // I2C communications #include #include #include #define DS1307_ADDRESS 0x68 //default address of the 1307 RTC module #define BRIGHTNESS 2 // define max brightness - higher number is brighter. If the number is too high it will exceed current draw of Arduino Adafruit_NeoPixel strip12 = Adafruit_NeoPixel(12, 3, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel strip24 = Adafruit_NeoPixel(24, 2, NEO_GRB + NEO_KHZ800); RTC_DS1307 RTC; // Establish clock object DateTime Clock; // Holds current clock time byte one; //variable used to point to time setting for minutes in DS1307 byte two; //variable used to point to time setting for minutes in DS1307 byte hourval_set; // holds the hour set time byte minuteval_set; // holds the minute set time uint8_t brightness; uint32_t pixelsecond; uint8_t Time_Set_Active; void setup() { pinMode(4, INPUT_PULLUP); // declare pin 4 to be an input with internal pullups (Red Wire - Decrement Hour Switch): pinMode(5, INPUT_PULLUP); // declare pin 5 to be an input with internal pullups (Blue Wire - Increment Hour Switch): pinMode(6, INPUT_PULLUP); // declare pin 6 to be an input with internal pullups (Green Wire - Decrement Minute Switch): pinMode(7, INPUT_PULLUP); // declare pin 7 to be an input with internal pullups (White Wire - Increment Minute Switch): Wire.begin(); RTC.begin(); // Initialize clock Serial.begin(9600); // set up Serial library at 9600 bps for debugging strip12.begin(); strip12.show(); // Initialize all pixels to 'off' strip24.begin(); strip24.show(); // Initialize all pixels to 'off' one = 0x01; two = 0x02; brightness = 2; //***************************************************RTC Initial adjustment *************************************************** // Run this to set the time to the PC Time on Arduino power up - comment out and download once you set the time // RTC.adjust(DateTime(__DATE__, __TIME__)); } // end of setup void loop() { int Button_Hour_Dec = digitalRead(4); // Read the Decrement Hour Switch int Button_Hour_Inc = digitalRead(5); // Read the Increment Hour Switch int Button_Minute_Dec = digitalRead(6); // Read the Decrement Minute Switch int Button_Minute_Inc = digitalRead(7); // Read the Increment Minute Switch uint32_t red12 = strip12.Color(255, 0, 0); //define NeoPixel Red color uint32_t white12 = strip12.Color(127, 127, 127); //define NeoPixel White color uint32_t green12 = strip12.Color(0, 255, 0); //define NeoPixel Green color uint32_t blue12 = strip12.Color(0, 0, 255); //define NeoPixel Blue color uint32_t off12 = strip12.Color(0, 0, 0); //define NeoPixel No color uint32_t red24 = strip24.Color(255, 0, 0); //define NeoPixel Red color uint32_t white24 = strip24.Color(127, 127, 127); //define NeoPixel White color uint32_t green24 = strip24.Color(0, 255, 0); //define NeoPixel Green color uint32_t blue24 = strip24.Color(0, 0, 255); //define NeoPixel Blue color uint32_t off24 = strip24.Color(0, 0, 0); //define NeoPixel No color uint32_t minuteval24; // minute val uint32_t hourval24; // hour val val uint32_t hourval_plus1; // hour val + 1 uint8_t buttons; // button read value int yearval, monthval, dayval, hourval, minuteval, secondval; // holds the time DateTime Clock; // variable to hold the time Clock = RTC.now(); // get the RTC time yearval = Clock.year(); // Clock Year monthval = Clock.month(); // Clock Month dayval = Clock.day(); // Clock Day hourval = Clock.hour(); // Clock Hour minuteval = Clock.minute(); // Clock Minute secondval = Clock.second(); // Clock Second if (hourval > 11) hourval -= 12; // if hourval > 11 then hourval -= hourval - 12 this just makes it 12 hour clock hourval24 = (hourval * 2); //determine the red dot to illuminate for example 3:30 is (2 * hourval) = 6 so pixel is 6 is illuminated minuteval24 = (minuteval / 2.5); //determine the green dot to illuminate for example 3:33 is (minuteval / 2.5 = 13.2 so pixel is 13 is illuminated since remainder truncated if (Button_Hour_Inc == HIGH && Button_Hour_Dec == HIGH && Button_Minute_Inc == HIGH && Button_Minute_Dec == HIGH && Time_Set_Active == HIGH) Time_Set_Active = 0; { strip24.setPixelColor(0, off24); strip24.setPixelColor(1, off24); strip24.setPixelColor(2, off24); strip24.setPixelColor(3, off24); strip24.setPixelColor(4, off24); strip24.setPixelColor(5, off24); strip24.setPixelColor(6, off24); strip24.setPixelColor(7, off24); strip24.setPixelColor(8, off24); strip24.setPixelColor(9, off24); strip24.setPixelColor(10, off24); strip24.setPixelColor(11, off24); strip24.setPixelColor(12, off24); strip24.setPixelColor(13, off24); strip24.setPixelColor(14, off24); strip24.setPixelColor(15, off24); strip24.setPixelColor(16, off24); strip24.setPixelColor(17, off24); strip24.setPixelColor(18, off24); strip24.setPixelColor(19, off24); strip24.setPixelColor(20, off24); strip24.setPixelColor(21, off24); strip24.setPixelColor(22, off24); strip24.setPixelColor(23, off24); strip24.setPixelColor(24, off24); } //Neopixel control when no pushbuttons (switches) active - A value of High is not active if (Button_Hour_Inc == HIGH && Button_Hour_Dec == HIGH && Button_Minute_Inc == HIGH && Button_Minute_Dec == HIGH) { strip24.setBrightness(BRIGHTNESS); // set brightness level defined at top of program strip24.setPixelColor(minuteval24, green24); if (minuteval >= 30) { hourval_plus1 = hourval24 + 1; } if (minuteval < 30) { hourval_plus1 = hourval24; } strip24.setPixelColor(hourval_plus1, red24); strip24.show(); if (minuteval24 == hourval_plus1) { strip24.setPixelColor(hourval_plus1, blue24); strip24.setPixelColor(minuteval24, blue24); } strip24.show(); strip12.setBrightness(BRIGHTNESS); // set brightness level defined at top of program pixelsecond = secondval / 5; theaterChaseRainbow(25); strip12.setPixelColor(pixelsecond, white12); strip12.show(); delay(500); } //Check if the seconds just went to 0. If they did, turn off the clock hours/miuntes LEDs and start again if (secondval == 0 || secondval == 15 || secondval == 30 || secondval == 15) { strip24.setPixelColor(0, off24); strip24.setPixelColor(1, off24); strip24.setPixelColor(2, off24); strip24.setPixelColor(3, off24); strip24.setPixelColor(4, off24); strip24.setPixelColor(5, off24); strip24.setPixelColor(6, off24); strip24.setPixelColor(7, off24); strip24.setPixelColor(8, off24); strip24.setPixelColor(9, off24); strip24.setPixelColor(10, off24); strip24.setPixelColor(11, off24); strip24.setPixelColor(12, off24); strip24.setPixelColor(13, off24); strip24.setPixelColor(14, off24); strip24.setPixelColor(15, off24); strip24.setPixelColor(16, off24); strip24.setPixelColor(17, off24); strip24.setPixelColor(18, off24); strip24.setPixelColor(19, off24); strip24.setPixelColor(20, off24); strip24.setPixelColor(21, off24); strip24.setPixelColor(22, off24); strip24.setPixelColor(23, off24); strip24.setPixelColor(24, off24); } if (Button_Hour_Inc == HIGH && Button_Hour_Dec == HIGH && Button_Minute_Inc == HIGH && Button_Minute_Dec == HIGH && Time_Set_Active == HIGH) Time_Set_Active = 0; { strip24.setPixelColor(0, off24); strip24.setPixelColor(1, off24); strip24.setPixelColor(2, off24); strip24.setPixelColor(3, off24); strip24.setPixelColor(4, off24); strip24.setPixelColor(5, off24); strip24.setPixelColor(6, off24); strip24.setPixelColor(7, off24); strip24.setPixelColor(8, off24); strip24.setPixelColor(9, off24); strip24.setPixelColor(10, off24); strip24.setPixelColor(11, off24); strip24.setPixelColor(12, off24); strip24.setPixelColor(13, off24); strip24.setPixelColor(14, off24); strip24.setPixelColor(15, off24); strip24.setPixelColor(16, off24); strip24.setPixelColor(17, off24); strip24.setPixelColor(18, off24); strip24.setPixelColor(19, off24); strip24.setPixelColor(20, off24); strip24.setPixelColor(21, off24); strip24.setPixelColor(22, off24); strip24.setPixelColor(23, off24); strip24.setPixelColor(24, off24); } //Large Neopixel Hours and Minutes strip24.setBrightness(BRIGHTNESS); // set brightness level defined at top of program strip24.setPixelColor(minuteval24, green24); if (minuteval >= 30) { hourval_plus1 = hourval24 + 1; } if (minuteval < 30) { hourval_plus1 = hourval24; } strip24.setPixelColor(hourval_plus1, red24); strip24.show(); if (minuteval24 == hourval_plus1) { strip24.setPixelColor(hourval_plus1, blue24); strip24.setPixelColor(minuteval24, blue24); } strip24.show(); // *************************************** Update Hour/Minute and set RTC *************************************** if (Button_Hour_Inc == LOW && Button_Hour_Dec == HIGH && Button_Minute_Inc == HIGH && Button_Minute_Dec == HIGH) { // if increment pressed, increment hours Time_Set_Active = 1; if (hourval_set < 12) { hourval_set = hourval_set + 1; delay (100); } if (hourval_set >= 12) { hourval_set = 0; } // setDateTime_hours(); Wire.beginTransmission(DS1307_ADDRESS); Wire.write(two); //write 2 for hours Wire.write(decToBcd(hourval_set)); Wire.endTransmission(); delay(350); } if (Button_Hour_Inc == HIGH && Button_Hour_Dec == LOW && Button_Minute_Inc == HIGH && Button_Minute_Dec == HIGH) { // if decrement pressed, decrement hours Time_Set_Active = 1; if (hourval_set > 0) { hourval_set = hourval_set - 1; delay (100); } if (hourval_set < 0) { hourval_set = 11; } // setDateTime_hours(); Wire.beginTransmission(DS1307_ADDRESS); Wire.write(two); //write 2 for hours Wire.write(decToBcd(hourval_set)); Wire.endTransmission(); delay(350); } if (Button_Hour_Inc == HIGH && Button_Hour_Dec == HIGH && Button_Minute_Inc == LOW && Button_Minute_Dec == HIGH) { // if increment pressed, increment minutes Time_Set_Active = 1; if (minuteval_set < 60) { minuteval_set = minuteval_set + 1; delay (50); } if (minuteval_set >= 60) { minuteval_set = 0; } // setDateTime_minutes(); Wire.beginTransmission(DS1307_ADDRESS); Wire.write(one); //write 1 for minutes Wire.write(decToBcd(minuteval_set)); Wire.endTransmission(); delay(250); } if (Button_Hour_Inc == HIGH && Button_Hour_Dec == HIGH && Button_Minute_Inc == HIGH && Button_Minute_Dec == LOW) { // if decrement pressed, decrement minutes Time_Set_Active = 1; if (minuteval_set > 0) { minuteval_set = minuteval_set - 1; delay (50); } if (minuteval_set <= 0) { minuteval_set = 59; } // setDateTime_minutes(); Wire.beginTransmission(DS1307_ADDRESS); Wire.write(one); //write 1 for minutes Wire.write(decToBcd(minuteval_set)); Wire.endTransmission(); delay(250); } // This is here for serial debug as needed // Serial.print("Button_Hour_Inc: "); Serial.print(Button_Hour_Inc); Serial.print('\n'); // Serial.print("Button_Hour_Dec: "); Serial.print(Button_Hour_Dec); Serial.print('\n'); // Serial.print("Button_Minute_Inc: "); Serial.print(Button_Minute_Inc); Serial.print('\n'); // Serial.print("Button_Minute_Dec: "); Serial.print(Button_Minute_Dec); Serial.print('\n'); } // end of main loop //Flash Small NeoPixel Seconds Ring void theaterChaseRainbow(uint8_t wait) { for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel for (int q=0; q < 3; q++) { for (int i=0; i < strip12.numPixels(); i=i+3) { strip12.setBrightness(BRIGHTNESS); // set brightness level strip12.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on } strip12.setBrightness(BRIGHTNESS); // set brightness level defined at top of program strip12.show(); delay(2); } } } //ChronoDot Conversion byte decToBcd(byte val) { // Convert normal decimal numbers to binary coded decimal - used for DS1307 return ( (val / 10 * 16) + (val % 10) ); } byte bcdToDec(byte val) { // Convert binary coded decimal to normal decimal numbers - used for DS1307 return ( (val / 16 * 10) + (val % 16) ); } // The colours are a transition r - g - b - back to r. uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip12.Color(255 - WheelPos * 3, 0, WheelPos * 3); } else if(WheelPos < 170) { WheelPos -= 85; return strip12.Color(0, WheelPos * 3, 255 - WheelPos * 3); } else { WheelPos -= 170; return strip12.Color(WheelPos * 3, 255 - WheelPos * 3, 0); } }