/ / Introduction
The DS1307 is a real time clock chip. This means that you just have to attach a quartz watch crystal to it, and it'll keep time for you. RTC chips are divided into two categories; those that keep time by counting seconds (usually as a 32 bit number) since some specific start point, and those that count seconds, minutes, hours, days, months, and years. The DS1307 is of the latter type. This means that it stores the time as seconds : minutes : hours (12 or 24 hour) : day of the week : day of the month : month : year. It also knows how many days are in each month, and even knows about leap years out to 2100.
The Sparkfun board that has a surface mount DS1307 on top, and a battery clip underneath.
4-seven segment LED Display
Part
- 4-seven segment LED display
- 8-bit shift register
- 6 220Ω resistors
- 4 push buttons
- 4 10K Ω resistors
- Wires
- Arduino
- Turn over the 4-seven-segment LED display and identify pins 1 and 16
- Plug the display into a breadboard
- Connect power and ground from your arduino to your bread board
- Connect your buttons to pins 2-5 of your arduino
- Place the 8-bit shift register in your breadboard
- Here is a diagram of the 4-seven segment display:
1: Digit 1 16: B 2: Digit 2 15: G 3: D 14: A 4: Colon Anode 13: C 5: E 12: Colon Cathode 6: Digit 3 11: F 7: Decimal Point 10: Apostrophe Anode 8: Digit 4 9: Apostrophe Cathode
- Wire up the 8-bit shift register like this:
1: display's B 16: 5V 2: display's C 15: display's A 3: display's D 14: arduino's dataPin (11) 4: display's E 13: Gnd 5: display's F 12: arduino's latchPin (8) 6: display's G 11: arduino's clockPin (12) 7: display's DP 10: 5V 8: Gnd 9: none
- Connect arduino pin 6 to a 220Ω resistor and connect the other side to The Display's Digit 1 pin
- Connect arduino pin 7 to a 220Ω resistor and connect the other side to The Display's Digit 2 pin
- Connect arduino pin 10 to a 220Ω resistor and connect the other side to The Display's Digit 3 pin
- Connect arduino pin 13 to a 220Ω resistor and connect the other side to The Display's Digit 4 pin
- Connect pin 12 of the Display to GND through a 220Ω resistor
- Open Arduino and add the following to your clock code:
#include "Wire.h" #define DS1307_I2C_ADDRESS 0x68 //add this #include <Button.h> //Pin connected to ST_CP of 74HC595 int latchPin = 8; //Pin connected to SH_CP of 74HC595 int clockPin = 12; ////Pin connected to DS of 74HC595 int dataPin = 11; byte data; byte dataArray[10]; //fill in these values int digit1Pin = _; int digit2Pin = _; int digit3Pin = _; int digit4Pin = __; int minutes_ones; int hours_ones; int minutes_tens; int hours_tens; //fill in these buttons Button minForward=Button(_,PULLDOWN); Button minBack=Button(_,PULLDOWN); Button hourForward=Button(_,PULLDOWN); Button hourBack=Button(_,PULLDOWN); byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; // store last time LED was updated long previousMillis = 0; //how often do you want to get the time (milliseconds) long interval = _____; //add this // Convert normal decimal numbers to binary coded decimal byte decToBcd(byte val){ return ( (val/10*16) + (val%10) ); } //add this // Convert binary coded decimal to normal decimal numbers byte bcdToDec(byte val){ return ( (val/16*10) + (val%16) ); } //add this void setDateDs1307(byte second, // 0-59 byte minute, // 0-59 byte hour, // 1-23 byte dayOfWeek, // 1-7 byte dayOfMonth, // 1-28/29/30/31 byte month, // 1-12 byte year) // 0-99 { Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.send(0); Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock Wire.send(decToBcd(minute)); Wire.send(decToBcd(hour)); // If you want 12 hour am/pm you need to set // bit 6 (also need to change readDateDs1307) Wire.send(decToBcd(dayOfWeek)); Wire.send(decToBcd(dayOfMonth)); Wire.send(decToBcd(month)); Wire.send(decToBcd(year)); Wire.endTransmission(); } // Gets the date and time from the ds1307 void getDateDs1307(byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayOfMonth, byte *month, byte *year){ // Reset the register pointer Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.send(0); Wire.endTransmission(); Wire.requestFrom(DS1307_I2C_ADDRESS, 7); // A few of these need masks because certain bits are control bits *second = bcdToDec(Wire.receive() & 0x7f); *minute = bcdToDec(Wire.receive()); *hour = bcdToDec(Wire.receive() & 0x3f); //& 0x3f Need to change this if 12 hour am/pm *dayOfWeek = bcdToDec(Wire.receive()); *dayOfMonth = bcdToDec(Wire.receive()); *month = bcdToDec(Wire.receive()); *year = bcdToDec(Wire.receive()); } void setup(){ //add this pinMode(latchPin, OUTPUT); Wire.begin(); Serial.begin(9600); // Change these values to what you want to set your clock to. // You probably only want to set your clock once and then remove // the setDateDs1307 call. minute = __; hour = __; second = 0; dayOfWeek = 5; dayOfMonth = 17; month = 4; year = 8; setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); pinMode(digit1Pin, OUTPUT); pinMode(digit2Pin, OUTPUT); pinMode(digit3Pin, OUTPUT); pinMode(digit4Pin, OUTPUT); dataArray[0] = 0xC0; //11000000 dataArray[1] = 0xf9; //01100000 dataArray[2] = 0xA4; //11011101 dataArray[3] = 0xB0; //10110000 dataArray[4] = 0x99; //10011001 dataArray[5] = 0x92; //10010010 dataArray[6] = 0x82; //10000010 dataArray[7] = 0xF8; //11111000 dataArray[8] = 0x80; //10000000 dataArray[9] = 0x90; //10010000 } //add this void addHour(){ if(hour<23){ hour++; }else{ hour=0; } setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); } //add this void subtractHour(){ if(hour>0){ hour--; }else{ hour=0; } setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); } //create an addMin function //create a subtractMin function void loop(){ if (millis() - previousMillis > interval) { // remember the last time you blinked the LED previousMillis =millis(); getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); } display_time(); //add the following conditionals if(minForward.uniquePress()){ addMin(); } if(minBack.uniquePress()){ subtractMin(); } if(hourForward.uniquePress()){ addHour(); } if(hourBack.uniquePress()){ subtractHour(); } } //add this method void setDigit(int digitPin, int value){ digitalWrite(latchPin, 0); shiftOut(dataPin, clockPin, dataArray[value]); digitalWrite(latchPin, 1); digitalWrite(digitPin, HIGH); delay(1); digitalWrite(digitPin, LOW); } //add this method void shiftOut(int myDataPin, int myClockPin, byte myDataOut) { // This shifts 8 bits out MSB first, //on the rising edge of the clock, //clock idles low //internal function setup int i=0; int pinState; pinMode(myClockPin, OUTPUT); pinMode(myDataPin, OUTPUT); //clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin, 0); digitalWrite(myClockPin, 0); //for each bit in the byte myDataOut //NOTICE THAT WE ARE COUNTING DOWN in our for loop //This means that %00000001 or "1" will go through such //that it will be pin Q0 that lights. for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); //if the value passed to myDataOut and a bitmask result // true then... so if we are at i=6 and our value is // %11010100 it would the code compares it to %01000000 // and proceeds to set pinState to 1. if ( myDataOut & (1< //replace display_time() with the following: void display_time() { // Function to display the time getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); minutes_ones = int(minute) % 10; // Get the 1's digit of seconds if (int(minute)>=10){ // If seconds greater than 10 minutes_tens = int(minute) / 10; } // Get 10's digit of seconds else { minutes_tens = 0; } // Otherwise 10s is 0 byte hourModded=hour%12; hours_ones = hourModded % 10; // Repeat for minutes if (hourModded>=10){ hours_tens =hourModded / 10 ; } else { hours_tens = 0; } setDigit(digit4Pin,minutes_ones); // Send digits to LEDs setDigit(digit3Pin,minutes_tens); setDigit(digit2Pin,hours_ones); if(hours_tens>0){ setDigit(digit1Pin,hours_tens); } }
//I2C
I2C is a serial data bus protocol that allows multiple devices to connect to each other with fairly slow data transfer rates. These slow data transfer rates are fast enough for many devices and allow the bus to be very simple to implement. The real beauty of this protocol is that you can control up to 112 devices with just two wires from a microcontroller. Many microcontrollers have a libraries to support I2C; on Arduino the official Wire library handles the details for you.

In this setup, the Arduino is the master and the Real-time clock module is the slave device on the I2C bus. Arduino has a library called Wire that handles all the details of the I2C protocol. Wire uses analog pin 4 for the Serial Data (SDA) connection and analog pin 5 for the Serial Clock (SCL) connection. The I2C protocol defines the bus as an open drain bus, which means you would have needed to use pull-up resistors on each of the two bus wires if the Arduino did not have built-in pull-up resistors for these pins.
This code has two main functions for accessing the DS1307. One sets the time and date, and the other gets the time and date. The DS1307 returns it's numbers coded in binary-coded decimal (BCD). This code also converts the numbers returned from the DS1307 out of BCD for you. If all you want to do is display the time BCD is probably better. If you're using it to decide when to run events, it’s better to work with normal numbers.
Parts
- DS1307 Real-time clock
- Wires
- Arduino
//
///
// Maurice Ribble
// 4-17-2008
// http://www.glacialwanderer.com/hobbyrobotics
// This code tests the DS1307 Real Time clock on the Arduino board.
// The ds1307 works in binary coded decimal or BCD. You can look up
// bcd in google if you aren't familior with it. There can output
// a square wave, but I don't expose that in this code. See the
// ds1307 for it's full capabilities.
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val){
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val){
return ( (val/16*10) + (val%16) );
}
// Stops the DS1307, but it has the side effect of setting seconds to 0
// Probably only want to use this for testing
/*void stopDs1307(){
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(0x80);
Wire.endTransmission();
}*/
// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour)); // If you want 12 hour am/pm you need to set
// bit 6 (also need to change readDateDs1307)
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.endTransmission();
}
// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}
void setup(){
Wire.begin();
Serial.begin(9600);
// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDs1307 call.
second = 45;
minute = _;
hour = _;
dayOfWeek = _;
dayOfMonth = _;
month = _;
year = _;
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}
void loop(){
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
Serial.print(hour, DEC);
Serial.print(":");
Serial.print(minute, DEC);
Serial.print(":");
Serial.print(second, DEC);
Serial.print(" ");
Serial.print(month, DEC);
Serial.print("/");
Serial.print(dayOfMonth, DEC);
Serial.print("/");
Serial.print(year, DEC);
Serial.print(" Day_of_week:");
Serial.println(dayOfWeek, DEC);
delay(1000);
}
//Setting the Time
Assuming the switches are wired as shown:
close SW0 and while closed SW1 and SW2 will increment the hours and minutes as shown on the terminal. Release/open SW0 and new time will be written to the DS1307.
When bit 6 is zero the clock is in 24-hour mode.
/*Reads the value from a Real Time Clock (RTC) DS1307 and displays it in the serial monitor
*
*Created by D. Sjunnesson 1scale1.com d.sjunnesson (at) 1scale1.com
*
*Created with combined information from
*http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1180908809
*http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1191209057
*
*
*Big credit to mattt (please contact me for a more correct name...) from the Arduino forum
*which has written the main part of the library which I have modified
*
*/
#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(57600);
/* // update time/date constants and uncomment block to set new time & date
RTC.stop();
RTC.set(DS1307_SEC,1); //set the seconds
RTC.set(DS1307_MIN,50); //set the minutes
RTC.set(DS1307_HR,0); //set the hours note 24 hour clock
RTC.set(DS1307_DOW,5); //set the day of the week
RTC.set(DS1307_DATE,14); //set the date
RTC.set(DS1307_MTH,8); //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);
}
//
#include <Button.h>
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
byte data;
byte dataArray[10];
//holders for infromation you're going to pass to shifting function
int minutes_ones;
int hours_ones;
int minutes_tens; // Initialise values for tens and ones units of m,s
int hours_tens;
int digit1Pin = 6; //can't use pin 1 since it's TX?
int digit2Pin = 7;
int digit3Pin = 9;
int digit4Pin = 10;
Button minForward=Button(2,PULLDOWN);
Button minBack=Button(3,PULLDOWN);
Button hourForward=Button(4,PULLDOWN);
Button hourBack=Button(5,PULLDOWN);
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// store last time LED was updated
long previousMillis = 0;
// interval at which to blink (milliseconds)
long interval = 1000;
/*
4 Digit 7 Segment display from Sparkfun
http://www.sparkfun.com/commerce/product_info.php?products_id=9480
1: Digit 1 16: B
2: Digit 2 15: G
3: D 14: A
4: Colon Anode 13: C
5: E 12: Colon Cathode
6: Digit 3 11: F
7: Decimal Point 10: Apostrophe Anode
8: Digit 4 9: Apostrophe Cathode
8 Bit Shift Register
1: display's B 16: 5V
2: display's C 15: display's A
3: display's D 14: arduino's dataPin
4: display's E 13: Gnd
5: display's F 12: arduino's latchPin
6: display's G 11: arduino's clockPin
7: display's DP 10: 5V
8: Gnd 9: none
*************
Display's Cathode goes to ground via resistor
Display's Anode goes to digital out
Digit pins go to digital out via resistor
Segment pins (A-G) go to digital out or shift register out (0 is on)
original shift reg code:
http://arduino.cc/en/Tutorial/ShftOut13
helpful schematic:
http://www.modxhost.com/595and4021.jpg
*/
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val){
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val){
return ( (val/16*10) + (val%16) );
}
// Stops the DS1307, but it has the side effect of setting seconds to 0
// Probably only want to use this for testing
/*void stopDs1307(){
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(0x80);
Wire.endTransmission();
}*/
// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour)); // If you want 12 hour am/pm you need to set
// bit 6 (also need to change readDateDs1307)
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.endTransmission();
}
// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year){
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f); //& 0x3f Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}
void setup(){
//byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
Serial.begin(9600);
// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDs1307 call.
second = 0;
minute = 45;
hour = 17;
dayOfWeek = 5;
dayOfMonth = 17;
month = 4;
year = 8;
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
pinMode(latchPin, OUTPUT);
pinMode(digit1Pin, OUTPUT);
pinMode(digit2Pin, OUTPUT);
pinMode(digit3Pin, OUTPUT);
pinMode(digit4Pin, OUTPUT);
dataArray[0] = 0xC0;
dataArray[1] = 0xf9; //01100000
dataArray[2] = 0xA4; //11011101
dataArray[3] = 0xB0; //10110000
dataArray[4] = 0x99; //10011001
dataArray[5] = 0x92; //10010010
dataArray[6] = 0x82; //10000010
dataArray[7] = 0xF8; //11111000
dataArray[8] = 0x80; //10000000
dataArray[9] = 0x90; //10010000
//function that blinks all the LEDs
//gets passed the number of blinks and the pause time
// blinkAll(2,500);
}
void addHour(){
if(hour<23){
hour++;
}else{
hour=0;
}
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}
void subtractHour(){
if(hour>0){
hour--;
}else{
hour=0;
}
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}
void addMin(){
if(minute<59){
minute++;
}else{
minute=0;
}
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}
void subtractMin(){
if(minute>0){
minute--;
}else{
minute=0;
}
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}
void loop(){
// byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
if(minForward.uniquePress()){
addMin();
}
if(minBack.uniquePress()){
subtractMin();
}
if(hourForward.uniquePress()){
addHour();
}
if(hourBack.uniquePress()){
subtractHour();
}
if (millis() - previousMillis > interval) {
// remember the last time you blinked the LED
previousMillis =millis();
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
}
display_time();
}
void setDigit(int digitPin, int value){
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, dataArray[value]);
digitalWrite(latchPin, 1);
digitalWrite(digitPin, HIGH);
delay(1);
digitalWrite(digitPin, LOW);
}
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut�
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}
void display_time() { // Function to display the time
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
minutes_ones = int(minute) % 10; // Get the 1's digit of seconds
if (int(minute)>=10){ // If seconds greater than 10
minutes_tens = int(minute) / 10;
} // Get 10's digit of seconds
else {
minutes_tens = 0;
} // Otherwise 10s is 0
hours_ones = hour % 10; // Repeat for minutes
if (hour>=10){
hours_tens =hour / 10 ;
}
else {
hours_tens = 0;
}
Serial.print(hours_tens);
Serial.print(hours_ones);
Serial.print(":");
Serial.print(minutes_tens);
Serial.println(minutes_ones);
setDigit(digit4Pin,minutes_ones); // Send digits to LEDs
setDigit(digit3Pin,minutes_tens);
setDigit(digit2Pin,hours_ones);
if(hours_tens>0){
setDigit(digit1Pin,hours_tens);
}
}
Sources:KENNETH FINNEGAN
An I2C Bus Example Using the DS1307 Real-Time Clock from http://www.glacialwanderer.com/hobbyrobotics/?p=12
An I2C Bus Example Using the DS1307 Real-Time Clock from http://www.glacialwanderer.com/hobbyrobotics/?p=12