Go Down

Topic: help with 74HC595 controlling induvial leds (Read 615 times) previous topic - next topic

hi im tinkering around with a 74HC595 chip and i was trying to figure out how to controll induvial leds. all the guides about these chips are just about understanding how it works and not how to program it. I understand how it shifts in data, but I am unable to creat a correct code to turn induvial leds on.


with the code below i was able to turn on led #1 , but when i was unable to turn any single one on..


//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 i = 0;i < 2; i++) {
    // 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,00000001, i); 

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

Osgeld

shiftOut(dataPin, clockPin,00000001, i); 

toss a B in front of 00000001 to tell the compiler that is a Binary representation of the number

shiftOut(dataPin, clockPin,B00000001, i); 
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

So if I wanted to turn just led #8 on I would change B00000001 to B10000000? That's it?

Osgeld

#3
Dec 27, 2012, 06:24 am Last Edit: Dec 27, 2012, 06:28 am by Osgeld Reason: 1
if its wired correctly ... ayep

actually you have the function wrong

shiftOut(dataPin, clockPin, bitOrder, value)

so

shiftOut(dataPin,ClockPin, MSBFIRST (or LSBFIRST), B00000001);

http://arduino.cc/en/Reference/ShiftOut
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

ok i think i get it now. using this code i was able to turn one leds and make them flash at different intervals.

//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 i = 0;i < 256; i++) {
    // 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, B01000000); 
   //take the latch pin high so the LEDs will light up:
    digitalWrite(latchPin, HIGH);
    delay(500);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin,clockPin,MSBFIRST, B00000001);
    digitalWrite(latchPin, HIGH);
    delay(200);
    digitalWrite(latchPin,LOW);
    shiftOut(dataPin,clockPin,MSBFIRST,B00000100);
    digitalWrite(latchPin, HIGH);
  delay(500);

}} 


 


UKHeliBob

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.


PaulS


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy