LED RTC

Hi,

First post, so please forgive me if I do anything wrong! I'm trying to get a simple LED clock working with a ds1307 and 4 discrete common anode 7 segment displays. The ds1307 is working fine and i can get the serial output of the time and date. I have written some code to display on the LED's and this works as well. I have managed to separate the minutes in to units and tens - and also to separate the hours similarly. This all works fine when I put this to serial output, however, when i pass the variables to the LED's all i get is zero's. Has anyone any idea please. I'm sure i'm doing something stupid! Please excuse the sloppy code.

// #include <Wire.h>
#include "RTClib.h"

//#if defined(ARDUINO_ARCH_SAMD)  // for Zero, output on USB Serial console
//#define Serial SerialUSB
//#endif
int HOUR, MINUTE;
int units, tens, hundreds, thousands;
int COUNT=0;//count integer for 0-9 increment
RTC_DS1307 rtc;

//                   a  b  c  d  e  f  g
const byte pins[] = {2, 3, 4, 5, 6, 7, 8};
const byte digits[] = {
  //gfedcba
  0b0111111,  // 0
  0b0000110,  // 1
  0b1011011,  // 2
  0b1001111,  // 3
  0b1100110,  // 4
  0b1101101,  // 5
  0b1111101,  // 6
  0b0100111,  // 7
  0b1111111,  // 8
  0b1101111   // 9
};

void displayNumber(byte number) {
  number = number % 10;   // hold the number within array bounds
  byte d = digits[number];
  for (byte i = 0; i < sizeof(pins); i++) {
    digitalWrite(pins[i], bitRead(d, i));  // turn segments on or off
  }
}

void setup () {
// while (!Serial);  
//  Serial.begin(57600);
//  if (! rtc.begin()) {
//    Serial.println("Couldn't find RTC");
//   while (1);
//  }
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //set time from computer
  //rtc.adjust(DateTime(2014, 1, 21, 14, 41, 10));

 pinMode(2, OUTPUT); // Seg A
 pinMode(3, OUTPUT); // Seg B
 pinMode(4, OUTPUT); // Seg C
 pinMode(5, OUTPUT); // Seg D
 pinMode(6, OUTPUT); // Seg E
 pinMode(7, OUTPUT); // Seg F
 pinMode(8, OUTPUT); // Seg G
 pinMode(9, OUTPUT); // Digit 1
 pinMode(10, OUTPUT); // Digit 2
 pinMode(11, OUTPUT); // Digit 3
 pinMode(12, OUTPUT); // Digit 4

#define segA 2// connecting segment A to PIN2
#define segB 3// connecting segment B to PIN3
#define segC 4// connecting segment C to PIN4
#define segD 5// connecting segment D to PIN5
#define segE 6// connecting segment E to PIN6
#define segF 7// connecting segment F to PIN7
#define segG 8// connecting segment G to PIN8


}



void loop () {

 
  
  DateTime now = rtc.now();
  HOUR = now.hour();
  MINUTE = now.minute();
  
//Serial.print(thousands);
//Serial.print(hundreds);
//Serial.print(':'); 
//Serial.print(tens);
//Serial.print(units);  
//Serial.print(unitsD);
//Serial.println();
//delay(1000);
  
  if (HOUR < 10)
  {
    hundreds = HOUR;
    thousands  = HOUR/10;
  }
  else if (HOUR >=  10 && HOUR < 24)
  {
    hundreds = HOUR % 10;
    thousands = HOUR / 10;
  }
  if (MINUTE <= 9)
  {
    units = (MINUTE);
    tens = (MINUTE/10);
  }

  else if (MINUTE > 9 && MINUTE <= 60)
  {
    units = (MINUTE % 10);
    tens = (MINUTE / 10);
  }


digitalWrite(9, HIGH); 
displayNumber(units);
delay (5);
digitalWrite(9, LOW); 

digitalWrite(10, HIGH); 
displayNumber(tens);
delay (5);
digitalWrite(10, LOW); 

digitalWrite(11, HIGH); 
displayNumber(hundreds);
delay (5);
digitalWrite(11, LOW); 

digitalWrite(12, HIGH); 
displayNumber(thousands);
delay (5);
digitalWrite(12, LOW); 
 
}

You can not comment out these lines. The library requires a call to rtc.begin().

//  if (! rtc.begin()) {
//    Serial.println("Couldn't find RTC");
//   while (1);
//  }

Thank you cattledog. That was all it was, i'd commented them out whilst trying to debug the LED code! Dumb mistake. Thanks again for your help :slight_smile: