0

I have a problem with the shift register 74HC595.

The sketch I use is able to enable a specific led (8 are connected).

When I enable led 0 to 7 it behaves like normally (they switch on when I enter the numbers).

However, for the led connected to pin 15 (other side of the ic, see layout) it behaves differently. When I switch this led on, ALL leds go off. When I retry, nothing happens. When I enable another led, after a short time (but can be seconds) the led for pin 15 is emitting light together with all others which where already enabled.

This seems like a malfunction in the IC (I checked already another led, another cable, another resistor). The only think I haven't checked is moving the IC to another position of the breadboard (that would take a lot of time since I have to rewrite everything). Is it possible I missed something or is the shift register broken?

The code to switch on a led:

void updateShiftRegister()
{
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, leds);
  digitalWrite(latchPin, HIGH);
}

where leds are the indices of the leds (0..7).

  • 1
    Please edit your question to include a Minimal, Complete, and Verifiable example of code, instead of just a snippet. Also, if “led 0 to 7” refers to 8 different LEDs (0 1 2 3 4 5 6 7) you will need to specify which pin each of those 8 LEDs are connected to. The question seems to say you have a ninth LED attached to Q0 on pin 15. – James Waldby - jwpat7 Feb 25 '17 at 1:00
  • 1
    Showing the wiring (and also a photo of your breadboard circuit) may help invesitgae on this issue. Also, I'd be curious to see code that sets leds value and how leds variable was declared (unsigned Vs. signed may have surprising effect on your code). – jfpoilpret Feb 25 '17 at 7:18
  • Thanks for all remarks, however, what I try is finding another project (instruction) for using it and check if I have the same problem; if still do, I can post it (and make a minimal example – Michel Keijzers Feb 25 '17 at 12:11
1

You cannot directly give an index (0..7) to a shift register if you want the index to represent the LED number to be switched on. You have to build a table similar to the following:

byte led[8] = {
0b00000001,
0b00000010,
0b00000100,
0b00001000,
0b00010000,
0b00100000,
0b01000000,
0b10000000
};

and later . . .

shiftOut(dataPin, clockPin, LSBFIRST, led[leds]);

where leds is a number 0..7

  • 3
    Or more cheaply shiftOut(dataPin, clockPin, LSBFIRST, bit(leds)); – Edgar Bonet Feb 25 '17 at 9:34
  • 1
    Nice. I knew there had to be an even quicker way for such a simple mapping. – 6v6gt Feb 25 '17 at 11:24
  • Thanks ... my example uses the shiftOut, but I will find another example and check if it also gives problems and than post the layout/full code if needed. – Michel Keijzers Feb 25 '17 at 12:12
  • Somehow it seems to work, after using another scheme (although it looked exactly equal). So I'm really not sure why the problem existed; now it seems to work ... wondering if I should remove the question since there might be useful information for others (regarding the table and shiftOut function. – Michel Keijzers Feb 25 '17 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.