It has run before, with the adjust edits in there. What I changed that made it not run successfully is I updated the code with new library functions as before I was using this code
#include <Wire.h> // specify use of Wire.h library.
#include <Time.h>
#include <DS1307RTC.h>
#define ONE_HZ_SW 8 // one Hz square wave from Ds1307
#define blinkPin 13
#define Sw0 4
#define Sw1 5
#define Sw2 6
int Sw0PW = 1; // pins to power LEDs on switches
int Sw1PW = 2;
int Sw2PW = 3;
int hrPins[] = {30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52};
int minPins[] = {31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53};
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600);
digitalWrite(blinkPin, 0);
pinMode(ONE_HZ_SW, INPUT_PULLUP);
pinMode(Sw0, INPUT_PULLUP); // for this use a slide switch
pinMode(Sw1, INPUT_PULLUP); // N.O. push button switch
pinMode(Sw2, INPUT_PULLUP); // N.O. push button switch
// Why on earth are you using digital pins to power LEDs that are always on? Just wire them directly to 5V already!
digitalWrite(Sw0PW, HIGH);
digitalWrite(Sw1PW, HIGH);
digitalWrite(Sw2PW, HIGH);
Serial.println("DS1307RTC Read Test");
Serial.println("-------------------");
}
void loop()
{
tmElements_t tm;
if (RTC.read(tm)) {
Serial.print("Ok, Time = ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(", Date (D/M/Y) = ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.println();
} else {
if (RTC.chipPresent()) {
Serial.println("The DS1307 is stopped. Please run the SetTime");
Serial.println("example to initialize the time and begin running.");
Serial.println();
} else {
Serial.println("DS1307 read error! Please check the circuitry.");
Serial.println();
}
delay(9000);
}
delay(1000);
if (!(digitalRead(Sw0))) set_time(); // hold the switch to set time
while(digitalRead(ONE_HZ_SW)); // wait for low
toggle(blinkPin);
tm.Hour %= 12; // Take the time modulo 12
for(int i = 0; i < 11; i++)
digitalWrite(hrPins[i], tm.Hour > i); // LED i turns on whenever the hour is at least i+1
digitalWrite(hrPins[11], tm.Hour == 0); // The last LED behaves differently from the others for some reason
tm.Minute /= 5; // We only care about the time in 15-minute increments
for(int i = 1; i < 12; i++)
digitalWrite(minPins[i], tm.Minute >= i);
digitalWrite(minPins[0], tm.Minute == 0); // The first pin behaves differently: it only turns on during the first 5 minutes
}
void print2digits(int number) {
if (number >= 0 && number < 10) {
Serial.write('0');
}
Serial.print(number);
}
// toggle the state on a pin
void toggle(int pinNum)
{
int pinState = digitalRead(pinNum);
pinState = !pinState;
digitalWrite(pinNum, pinState);
}
void set_time() {
byte minutes = 0;
byte hours = 0;
while (!digitalRead(Sw0)) // set time switch must be released to exit
{
while (!digitalRead(Sw1)) // set minutes
{
minutes++;
if ((minutes & 0x0f) > 9) minutes = minutes + 6;
if (minutes > 0x59) minutes = 0;
Serial.print("Minutes = ");
if (minutes >= 9) Serial.print("0");
Serial.println(minutes, HEX);
delay(750);
}
while (!digitalRead(Sw2)) // set hours
{
hours++;
if ((hours & 0x0f) > 9) hours = hours + 6;
if (hours > 0x23) hours = 0;
Serial.print("Hours = ");
if (hours <= 9) Serial.print("0");
Serial.println(hours, HEX);
delay(750);
}
// Note: you should use some function/library for this to make the code cleaner
Wire.beginTransmission(0x68); // activate DS1307
Wire.write(0); // where to begin
Wire.write(0x00); //seconds
Wire.write(minutes); //minutes
Wire.write(0x80 | hours); //hours (24hr time)
Wire.write(0x06); // Day 01-07
Wire.write(0x16); // Date 0-31
Wire.write(0x11); // month 0-12
Wire.write(0x13); // Year 00-99
Wire.write(0x10); // Control 0x10 produces a 1 HZ square wave on pin 7.
Wire.endTransmission();
}
}
and I needed to update sections where I was using a Wire.beginTransmission into using an actual RTC library