Examples - Electronic Bricks - Electronic Brick RTC -Clock

Add a real time to your project with the RTC - Clock Brick

That program gives you a basic understanding of how to use the realtime RTC clock Electronic Brick. Connect the RTC module to the IIC connector on chassis and program the code below, then you will get a clock.

More information about IIC/TWI library and RTC module is here:
http://www.arduino.cc/playground/Learning/I2C
http://www.arduino.cc/en/Reference/Wire
http://www.seeedstudio.com/depot/electronic-brick-real-time-clock-moduleds1307-p-491.html



#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>
// written by mattt on the Arduino forum and modified by D. Sjunnesson

void setup()
{
        Serial.begin(9600);

        RTC.stop();
        RTC.set(DS1307_SEC,1);        //set the seconds
        RTC.set(DS1307_MIN,23);     //set the minutes
        RTC.set(DS1307_HR,12);       //set the hours
        RTC.set(DS1307_DOW,4);       //set the day of the week
        RTC.set(DS1307_DATE,5);       //set the date
        RTC.set(DS1307_MTH,3);       //set the month
        RTC.set(DS1307_YR,9);         //set the year
        RTC.start();
}

void loop()
{

        Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the
        values by pushing in true
        Serial.print(":");
        Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
        Serial.print(":");
        Serial.print(RTC.get(DS1307_SEC,false));//read seconds
        Serial.print("      ");                 // some space for a more happy life
        Serial.print(RTC.get(DS1307_DATE,false));//read date
        Serial.print("/");
        Serial.print(RTC.get(DS1307_MTH,false));//read month
        Serial.print("/");
        Serial.print(RTC.get(DS1307_YR,false)); //read year
        Serial.println();

        delay(1000);

}

This website has been archived and is no longer maintained.