Created
July 29, 2014 03:52
-
-
Save buckeyeworldcitizen/3e4ab08eee9e72b83e4d to your computer and use it in GitHub Desktop.
rtc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib | |
#include <Wire.h> | |
#include "RTClib.h" | |
#include <Adafruit_NeoPixel.h> | |
#define pinhap 6 | |
#define pindean 7 | |
#define pinshel 8 | |
RTC_DS1307 RTC; | |
int led = 13; | |
int wait = 1; | |
Adafruit_NeoPixel strip_h = Adafruit_NeoPixel(13, pinhap, NEO_GRB + NEO_KHZ800); | |
Adafruit_NeoPixel strip_d = Adafruit_NeoPixel(4, pindean, NEO_GRB + NEO_KHZ800); | |
Adafruit_NeoPixel strip_s = Adafruit_NeoPixel(7, pinshel, NEO_GRB + NEO_KHZ800); | |
void setup () { | |
strip_h.begin(); | |
strip_d.begin(); | |
strip_s.begin(); | |
strip_h.show(); | |
strip_d.show(); | |
strip_s.show(); | |
Serial.begin(57600); | |
Wire.begin(); | |
RTC.begin(); | |
//pinMode(led, OUTPUT); | |
//int sec; | |
// if (! RTC.isrunning()) { | |
// Serial.println("RTC is NOT running!"); | |
// following line sets the RTC to the date & time this sketch was compiled | |
// RTC.adjust(DateTime(__DATE__, __TIME__)); | |
} | |
//} | |
void loop () { | |
//int sec; | |
DateTime now = RTC.now(); | |
Serial.print(now.year(), DEC); | |
Serial.print('/'); | |
Serial.print(now.month(), DEC); | |
Serial.print('/'); | |
Serial.print(now.day(), DEC); | |
Serial.print(' '); | |
Serial.print(now.hour(), DEC); | |
Serial.print(':'); | |
Serial.print(now.minute(), DEC); | |
Serial.print(':'); | |
Serial.print(now.second(), DEC); | |
Serial.println(); | |
Serial.print(" since 1970 = "); | |
Serial.print(now.unixtime()); | |
Serial.print("s = "); | |
Serial.print(now.unixtime() / 86400L); | |
Serial.println("d"); | |
// calculate a date which is 7 days and 30 seconds into the future | |
// DateTime future (now.unixtime() + 0 * 86400L + 30); | |
//sec = (now.second(), DEC); | |
// Serial.print(" now + 7d + 30s: "); | |
// Serial.print(future.year(), DEC); | |
// Serial.print('/'); | |
// Serial.print(future.month(), DEC); | |
// Serial.print('/'); | |
// Serial.print(future.day(), DEC); | |
// Serial.print(' '); | |
// Serial.print(future.hour(), DEC); | |
// Serial.print(':'); | |
// Serial.print(future.minute(), DEC); | |
// Serial.print(':'); | |
// Serial.print(future.second(), DEC); | |
// Serial.println(); | |
if (now.minute() >= 46 && (now.minute() <= 47)){ | |
rainbowCycle(20); | |
//digitalWrite(led, HIGH); | |
} | |
else{ | |
strip_h.Color(0, 0, 0); | |
//digitalWrite(led, LOW );} | |
Serial.print(now.minute(), DEC); | |
//Serial.print(sec); | |
//Serial.println(sec); | |
Serial.println(); | |
delay(3000); | |
} | |
// rainbowCycle(20); | |
//colorWipe(strip.Color(205, 155, 100), 10); | |
// strip.Color(205, 155, 100); | |
// }} | |
} | |
void colorWipe(uint32_t c, uint8_t wait) { | |
for(uint16_t i=0; i<strip_h.numPixels(); i++) { | |
strip_h.setPixelColor(i, c); | |
strip_h.show(); | |
delay(wait); | |
} | |
} | |
void rainbow(uint8_t wait) { | |
uint16_t i, j; | |
for(j=0; j<256; j++) { | |
for(i=0; i<strip_h.numPixels(); i++) { | |
strip_h.setPixelColor(i, Wheel((i+j) & 255)); | |
} | |
strip_h.show(); | |
delay(wait); | |
} | |
} | |
// Slightly different, this makes the rainbow equally distributed throughout | |
void rainbowCycle(uint8_t wait) { | |
uint16_t i, j; | |
for(j=0; j<256*1; j++) { // 5 cycles of all colors on wheel | |
for(i=0; i< strip_h.numPixels(); i++) { | |
strip_h.setPixelColor(i, Wheel(((i * 50 / strip_h.numPixels()) + j) & 255)); | |
// delayMicroseconds(150); | |
} | |
strip_h.show(); | |
} | |
// delay(150); | |
delay(wait); | |
} | |
// Input a value 0 to 255 to get a color value. | |
// The colours are a transition r - g - b - back to r. | |
uint32_t Wheel(byte WheelPos) { | |
if(WheelPos < 85) { | |
return strip_h.Color(WheelPos * 3, 255 - WheelPos * 3, 0); | |
} | |
else if(WheelPos < 170) { | |
WheelPos -= 85; | |
return strip_h.Color(255 - WheelPos * 3, 0, WheelPos * 3); | |
} | |
else { | |
WheelPos -= 170; | |
return strip_h.Color(0, WheelPos * 3, 255 - WheelPos * 3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment