I want to light any sequence of 24 LEDs. I've connected 3 SN74HC595N shift registers and am able to light which ever LEDs I desire by setting my variable "leds" to the corresponding binary number (0B000000001111111100000000 will light up the middle 8 LEDs).
My issue is the last 8 LEDs light up (half as bright) when the first register's LEDs are on(0b111111110000000000000000), the second register's LEDs are on (0B000000001111111100000000) or both 1st and 2nd register's LEDs are on (0B111000001111100000000).
I don't understand why and how to prevent this.
Thank you,
Michael
/*
74hc595
1 Q2
2 Q3
3 Q4
4 Q5
5 Q6
6 Q7
7 Q8
8 GND
9 DAISY CHAIN TO NEXT 14
10 +5v
11 CLOCK
12 LATCH
13 GND
14 DATA
15 Q1
16 +5
*/
#include <stdio.h>
int latchPin = 8;
int clockPin = 13;
int dataPin = 11;
unsigned long leds = 0; // Variable to hold the pattern of which LEDs are currently turned on or off
int Hr = 0;
int Min = 0;
int Hleds = 0;
int Mleds = 0;
void setup()
{
// Set all the pins of 74HC595 as OUTPUT
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
leds = 0B111111110000000000000000;
updateShiftRegister();
}
void updateShiftRegister() // Since only 3 registers, need only 24 bytes
{
unsigned int leds16 = int(leds);
unsigned int leds32 = int(leds >> 8);
byte low16LED = lowByte(leds16);
byte high16LED = highByte(leds16);
byte low32LED = lowByte(leds32);
byte high32LED = highByte(leds32);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, low16LED); // 3rd register
shiftOut(dataPin, clockPin, LSBFIRST, high16LED);// 2nd register
shiftOut(dataPin, clockPin, LSBFIRST, high32LED);// 1st register
digitalWrite(latchPin, HIGH);
}
Could you draw a schematic ?
The SN74HC595N might not be capable to drive the leds. The TPIC6B595 is made for leds: https://www.adafruit.com/product/457
Could you show a photo ?
Breadboards have often bad contacts and jumper wires can be broken.
Please don't include stdio.h.
Which Arduino board do you use ?
The binary notation for the C language is 0b111111110000000000000000.
There are variable types for a specific number of bits. I suggest to use "uint32_t" for 32 bits.
The shifting together with the bytes and lowByte() and highByte() are confusing.
The shiftOut shifts a byte. I think this code shows better what it does:
I've checked my connections and even replaced the IC with another, but still get the flickering. The appropriate LEDs light up as called for in the problem so I really don't suspect it to be a wiring issue.
My guess is it is something in the program that I just haven't found what stupid thing I'm doing that is wrong.
Please describe your wiring, or provide a photo. The most likely answers for poor visibility at the end of a string are:
you're not always writing to all 3 registers, so one isn't receiving the same data as frequently as the others
your power wiring (+5 and GND) to the '595's is high resistance, resulting in low voltage at the end of the run.
To test these possibilities, reverse the data wire only, such that the third register is first in line for data but still last in line for power. Did the problem move to the other register or not? You've got a data problem if it did, a power problem if it didnt.