Pages: [1]   Go Down
Author Topic: help with 74HC595 controlling induvial leds  (Read 476 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
  }}
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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); 
Logged


Offline Offline
Newbie
*
Karma: 1
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: December 27, 2012, 12:28:25 am by Osgeld » Logged


Offline Offline
Newbie
*
Karma: 1
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);

}} 
 

 
 
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4255
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you need the for loop ?
Logged

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

Offline Offline
Newbie
*
Karma: 1
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do I need the what?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49307
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Do I need the what?
Probably not.
Logged

Pages: [1]   Go Up
Jump to: