Pages: [1]   Go Down
Author Topic: Shift Register, 2 leds only  (Read 394 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 65
Posts: 2111
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
http://www.arduino.cc/en/Tutorial/ShiftOut

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


Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is how I've connected everything:

And I've used this code:

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!
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8473
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33402
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So what part of:-
Quote
Just forget about the capacitor,
Did you not understand?
Putting that capacitor on will destroy your arduino in time.

Quote
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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

______
Rob
Done! It's removed.

So what part of:-
Quote
Just forget about the capacitor,
Did you not understand?
Putting that capacitor on will destroy your arduino in time.

Quote
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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33402
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: