Created
April 2, 2016 14:06
-
-
Save mschlenker/d0fd407b871def760b6d19edc3d64c94 to your computer and use it in GitHub Desktop.
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
/* | |
RV8523 RTC (Real-Time-Clock) Example | |
Uno A4 (SDA), A5 (SCL) | |
Mega 20 (SDA), 21 (SCL) | |
Leonardo 2 (SDA), 3 (SCL) | |
Note: To enable the I2C pull-up resistors on the RTC-Breakout, the jumper J1 has to be closed. | |
*/ | |
#include <Wire.h> | |
#include <RV8523.h> | |
#include <Adafruit_NeoPixel.h> | |
#ifdef __AVR__ | |
#include <avr/power.h> | |
#endif | |
#define PIN 13 | |
#define BLUE strip.Color(0,0,255) | |
#define BLACK strip.Color(0,0,0) | |
#define GREEN strip.Color(0,255,0) | |
#define RED strip.Color(255,0,0) | |
#define WHITE strip.Color(255,255,255) | |
#define PIXELOFFSET 6 | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800); | |
RV8523 rtc; | |
void setup() | |
{ | |
//init Serial port | |
Serial.begin(9600); | |
while(!Serial); //wait for serial port to connect - needed for Leonardo only | |
//init RTC | |
Serial.println("Init RTC..."); | |
//set 12 hour mode | |
// rtc.set12HourMode(); | |
//set 24 hour mode | |
rtc.set24HourMode(); | |
//set the date+time (only one time) | |
//rtc.set(0, 05, 16, 2, 4, 2016); //08:00:00 24.12.2014 //sec, min, hour, day, month, year | |
//stop/pause RTC | |
// rtc.stop(); | |
//start RTC | |
rtc.start(); | |
//When the power source is removed, the RTC will keep the time. | |
rtc.batterySwitchOver(1); //battery switch over on | |
//When the power source is removed, the RTC will not keep the time. | |
// rtc.batterySwitchOver(0); //battery switch over off | |
strip.begin(); | |
strip.show(); | |
} | |
void loop() | |
{ | |
uint8_t sec, min, hour, day, month; | |
uint16_t year; | |
//get time from RTC | |
rtc.get(&sec, &min, &hour, &day, &month, &year); | |
//serial output | |
Serial.print("\nTime: "); | |
Serial.print(hour, DEC); | |
Serial.print(":"); | |
Serial.print(min, DEC); | |
Serial.print(":"); | |
Serial.print(sec, DEC); | |
Serial.print("\nDate: "); | |
Serial.print(day, DEC); | |
Serial.print("."); | |
Serial.print(month, DEC); | |
Serial.print("."); | |
Serial.print(year, DEC); | |
//wait a second | |
delay(1000); | |
setClock(hour, min, sec); | |
} | |
/* | |
#include <Adafruit_NeoPixel.h> | |
#ifdef __AVR__ | |
#include <avr/power.h> | |
#endif | |
#define PIN 13 | |
#define BLUE strip.Color(0,0,255) | |
#define BLACK strip.Color(0,0,0) | |
#define GREEN strip.Color(0,255,0) | |
#define RED strip.Color(255,0,0) | |
#define WHITE strip.Color(255,255,255) | |
#define PIXELOFFSET 6 | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800); | |
//void setup() { | |
// put your setup code here, to run once: | |
strip.begin(); | |
strip.show(); | |
} | |
//void loop() { | |
// put your min code here, to run repeatedly: | |
//strip.setPixelColor(6, BLUE); | |
//strip.show(); | |
delay(3000); | |
for (int i=0; i<24; i++) { | |
for (int j=0; j<60; j++) { | |
for (int k=0; k<60; k++){ | |
setClock(i, j, k); | |
delay(10); | |
} | |
} | |
} | |
} | |
*/ | |
void setClock (int hour, int minute, int sec) { | |
for(int i=0; i<12; i++){ | |
strip.setPixelColor(i, BLACK); | |
} | |
strip.setPixelColor((sec/5+PIXELOFFSET)%12, RED); | |
strip.setPixelColor((minute/5+PIXELOFFSET)%12, BLUE); | |
strip.setPixelColor((hour+PIXELOFFSET)%12, WHITE); | |
strip.show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment