Instantly share code, notes, and snippets.

What would you like to do?
Based on RV8523 RTC (Real-Time-Clock) Example from Watterott Electronic
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.
*2016/4/2 Modification for a Tutorial @Arduino/Genuino Day 2016 @Watterott electronic
*2016/4/4 Modification by Maik Hübscher
- configurable Led-count on LED-Ring
- Serial communication deactivable if neccessary
- LED dimming via const or Analog Input
Note: If Serial communication is deactivated RTC-Timesetup is not possible and had to be done externaly by unplugging the RTC.
#include <Wire.h>
#include <RV8523.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#define NeoPin 13 // Data out pin of the WS2812 Ring
#define AnalogIn A0 // AnalogIn for LED dimming
#define SerialData 1 // Send Data via UART 1=enable 0=disable
#define SerialBaud 9600 // Baudrate for communication
#define PIXELCOUNT 60 //Numbers of pixels
#define PIXELOFFSET 30 //Offset for first pixel
#define LiveDimActive 1 //Live dimming 1=Yes 0=No
#define DimMin 50 //Minimum dimming value 0-255
#define DimMax 255 //Maximum dimming value 0-255
//if LiveDimActive is deactivated, the Value of Dim is the Led-brightness
int Dim = 127; //Init Value for LED dimming
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXELCOUNT, NeoPin, NEO_GRB + NEO_KHZ800);
int Pos = 60 / PIXELCOUNT;
int PosHour = Pos * 5 ;
RV8523 rtc;
void setup()
if(SerialData >= 1){
//init Serial port
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
//set the date+time (only one time)
//rtc.set(0, 14, 1, 4, 4, 2016); //08:00:00 24.12.2014 //sec, min, hour, day, month, year
//stop/pause RTC
// rtc.stop();
//start RTC
//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
void loop()
uint8_t sec, min, hour, day, month;
uint16_t year;
//get time from RTC
rtc.get(&sec, &min, &hour, &day, &month, &year);
if(SerialData >=1){
//serial output
Serial.print("\nTime: ");
Serial.print(hour, DEC);
Serial.print(min, DEC);
Serial.print(sec, DEC);
Serial.print("\nDate: ");
Serial.print(day, DEC);
Serial.print(month, DEC);
Serial.print(year, DEC);
//wait a second
if(LiveDimActive >= 1){
Dim = analogRead(AnalogIn);
Dim = map(Dim, 0, 1023, DimMin, DimMax);
setClock(hour, min, sec);
* Subroutines
void setClock (int hour, int minute, int sec) {
for(int i=0; i<PIXELCOUNT; i++){
strip.setPixelColor(i, strip.Color(0,0,0)); //delete all LEDs
strip.setPixelColor((sec/Pos+PIXELOFFSET)%PIXELCOUNT, strip.Color(Dim,0,0));
strip.setPixelColor((minute/Pos+PIXELOFFSET)%PIXELCOUNT, strip.Color(0,0,Dim));
strip.setPixelColor((hour*PosHour+PIXELOFFSET)%PIXELCOUNT, strip.Color(Dim,Dim,Dim));;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment