Creating a Binary Clock With 8-bit Shift Registers [SOLVED]

Hello,

I have been using Arduino for a short time now (3 months) so this is my second project (the other being a videogame in a box type thing). I do have coding experience in other languages but need some assistance with Arduino.

I am attempting to build a binary (BCD) clock using shift registers (If you don’t know what a binary clock is, read this: http://en.wikipedia.org/wiki/Binary_clock). I am using three shift registers, one for each set of digits (Hours, Minutes, Seconds), but I am having trouble operating them all at once.

HARDWARE:
I am currently testing with an Arduino Uno but will be switching to an Arduino Pro Mini for the final product.
The shift registers’ serial number: SN74HC595NE4 (datasheet: http://www.ti.com/lit/ds/symlink/sn74hc595.pdf)

SETUP:

It is the same as the one found in the “Serial to Parallel Shifting-Out with a 74HC595” tutorial but with 7 LEDs and with the three highest digits being in a separate row on the right. In an arrangement like this:

I’ve tested this setup with some other code (Counting from 0 to 255) and it worked just fine, so the problem must be in my coding.

//WIP

RESULT:
All of the LEDs are turned off, but when the latch pin is removed, all of the LEDs come on, with the exception of one or two. The program seems to be doing something as it flickers off and back on at a consistent rate, and the LEDs that stay off seem to be following some pattern.

EDIT: I did not get any errors in the code which was odd, but I was able to deduce that there was in-fact, something wrong with it.

All help is extremely appreciated!
Thank you!
~Pyro

  secBin = sec1 + (sec2 * 8);

Should that be * 16?

One thing: just because your code compiles does not mean it will do what you think it should. A written paper with all the words spelled correctly does not guarantee it makes sense or is right.

WTH is this? Did that compile? It is not inside of a function, there's no way to read the pins during compile!

//Button controls
int minUp = digitalRead(buttonPinUp);
int minDown = digitalRead(buttonPinDown);

If you think that you can somehow assign a variable to a pin and the variable will change because the pin does then surprise, your code has to read the pin to a variable or use an interrupt (more complicated) to do the same.

Are you using a button to drive your clock, or an external oscillator? A button probably needs to be debounced.

You are going a long way around with your BCD. You should keep your values in BCD and do the math in those. BCD lets you put 2 digits in 1 byte using 4 bits for each digit. Yup, 1 byte each for HH MM SS. You need to understand bits and bit operations not just to do that well. There's a good tutorial: http://playground.arduino.cc/Code/BitMath

You don't need to use int for almost all of your variables. That's a bad habit on limited-memory devices.

Using a test sketch, can you reliably shift a byte out and get the leds to show the bits?

You can save pins and code. You can chain your 3 shift registers, clock in 24 bits and then latch using 3 SPI port pins, not needing to use MISO. All the registers use the same clock and latch lines. Data Out from the 1st register connects to Data In of the next, each added register acts as an extension. After that you just send a set of 3 bytes to make any change.

You could done with using array while coding.

And Ds1307 cheaper solution.

Sould this code

  if(timer > 999) {
    timer = 0;
    minutes += 1;

be seconds += 1;

I have scrolled up and down through your code and I can't figure out what you are using to keep time? Time (minutes or seconds?) just seems to be incremented after 999 iterations of loop(). Why not use millis()?

...R

Hi, thanks for the replies, it was late at night and this morning looking through the code I was thinking to myself "what the heck am I doing?" all of my problems were really obvious, I would just like to apologize for even posting this thread. But like I said Arduino isn't my fist language. I've pretty much rewrote the whole thing and got it working now, thanks to all.

~Pyro

Working on code when you’re tired or stuck is one of the great ways to write more bugs in than you get out.
But great that you woke up with a fresh mind and energy to see a good answer through!

Would it be too much to ask for the sake of people who do use the forum to find answers, if you would post yours?

Yes I was planning to do that, I just removed the old code to prevent confusion. I'm writing it now.