I followed the tutorial on controlling 8 LEDs using a SIPO SN74HC595N shift register on both Adafruit and Last Minute Engineer. I used a Sparkfun Pro Micro (Arduino Leonardo equivalent).
The problem is the LEDs are not lighting up in the way that I'm expecting it do it. Both guides said each LED will light up one after another. After all 8 are lit, all of them will turn off. Here is my result. Other LEDs will either dim up or down as the target LED turn on. I used the code provided from the guide and only changed the pinout number. The resistor values are the same for each color so it can't be the resistor. Anyone have any idea what's going on here?
/*
Test code for 74HC595N SIPO shift register. Used with Pro Micro
*/
int latchPin = 16;
int clockPin = 15;
int dataPin = 14;
int outputEnablePin = 10;
byte leds = 0; // Variable to hold the pattern of which LEDs are currently turned on or off
void setup()
{
// Set all the pins of 74HC595 as OUTPUT
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(outputEnablePin, OUTPUT);
outputEnablePin = LOW;
}
/*
* loop() - this function runs over and over again
*/
void loop()
{
leds = 0; // Initially turns all the LEDs off, by giving the variable 'leds' the value 0
updateShiftRegister();
delay(500);
for (int i = 0; i < 8; i++) // Turn all the LEDs ON one by one.
{
bitSet(leds, i); // Set the bit that controls that LED in the variable 'leds'
updateShiftRegister();
delay(500);
}
}
/*
* updateShiftRegister() - This function sets the latchPin to low, then calls the Arduino function 'shiftOut' to shift out contents of variable 'leds' in the shift register before putting the 'latchPin' high again.
*/
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}
Schematics:
The resistor values are the same for each color so it can't be the resistor.
What makes you think that? The current through the LED is dictated by the resistor value and the LED's forward voltage. The LED's forward voltage is dictated by the colour. Thus you need to size the resistor correctly for each colour of LED.