Shift Register, 2 leds only

Hello,

I have an Arduino Uno with a Shift Register (74HC595N).
I've tried multiple examples found here and edited them, but somehow I can't get it working.. all the leds are staying off, or will just on and stay on.

So my question is, can someone put me in the right direction to controll each seperate led.

Thanks in advance,
Peter!

Make sure the OE pin is tied to low and MR is tied to HIGH otherwise the outputs wont do anything.
If the OE (output enable ) is HIGH the outputs are in tri-state ( off ).

Can't really be much help without a circuit diagram or code you are using.
The examples I used worked without any modifications.

Just forget about the capacitor, it is not needed ( is also in the wrong spot )

This is how I've connected everything:

And I've used this code:

//**************************************************************//
//  Name    : shiftOutCode, Hello World                                
//  Author  : Carlyn Maw,Tom Igoe, David A. Mellis 
//  Date    : 25 Oct, 2006    
//  Modified: 23 Mar 2010                                 
//  Version : 2.0                                             
//  Notes   : Code for using a 74HC595 Shift Register           //
//          : to count from 0 to 255                           
//****************************************************************

//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;



void setup() {
  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  // count from 0 to 255 and display the number 
  // on the LEDs
  for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) {
    // take the latchPin low so 
    // the LEDs don't change while you're sending in bits:
    digitalWrite(latchPin, LOW);
    // shift out the bits:
    shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);  

    //take the latch pin high so the LEDs will light up:
    digitalWrite(latchPin, HIGH);
    // pause before next value:
    delay(500);
  }
}

And it's working perfectly, but what we want is to turn on the first 2 leds and all the other leds should be off. So, what do I have to modify to get the first to leds continuously on?

Thanks in advance!

Get rid of the 1uF cap on the latch signal.


Rob

So what part of:-

Just forget about the capacitor,

Did you not understand?
Putting that capacitor on will destroy your arduino in time.

but what we want is to turn on the first 2 leds and all the other leds should be off.

Have a variable that you shift out when you want to update the LEDs.
Use bit write and bit clear instructions to change the bits in the variable that you want to change then shift it out again.

Graynomad:
Get rid of the 1uF cap on the latch signal.


Rob

Done! It's removed.

Grumpy_Mike:
So what part of:-

Just forget about the capacitor,

Did you not understand?
Putting that capacitor on will destroy your arduino in time.

but what we want is to turn on the first 2 leds and all the other leds should be off.

Have a variable that you shift out when you want to update the LEDs.
Use bit write and bit clear instructions to change the bits in the variable that you want to change then shift it out again.

I think I understand, but not sure where to start.. would you be able to "show" an example of how to code this?

In your example the variable you are shifting out is called numberToDisplay
So that is the one you have to set the bits on. Currently you are just using it as a loop counter in a for statement.
Ditch all that and look up the bit set and bit clear instructions.
Apply these and then shift out.