Offline
Newbie
Karma: 1
Posts: 25
|
 |
« on: December 26, 2012, 11:51:27 pm » |
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
Faraday Member
Karma: 35
Posts: 3651
@ssh0le
|
 |
« Reply #1 on: December 27, 2012, 12:06:01 am » |
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
|
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
|
|
|
|
Offline
Newbie
Karma: 1
Posts: 25
|
 |
« Reply #2 on: December 27, 2012, 12:13:26 am » |
So if I wanted to turn just led #8 on I would change B00000001 to B10000000? That's it?
|
|
|
|
|
Logged
|
|
|
|
|
SE USA
Offline
Faraday Member
Karma: 35
Posts: 3651
@ssh0le
|
 |
« Reply #3 on: December 27, 2012, 12:24:39 am » |
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
|
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
|
|
|
|
Offline
Newbie
Karma: 1
Posts: 25
|
 |
« Reply #4 on: December 27, 2012, 04:11:51 pm » |
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
Edison Member
Karma: 55
Posts: 1601
May all of your blinks be without delay
|
 |
« Reply #5 on: December 27, 2012, 05:32:42 pm » |
Do you need the for loop ?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 1
Posts: 25
|
 |
« Reply #6 on: December 27, 2012, 09:08:42 pm » |
Do I need the what?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 336
Posts: 36476
Seattle, WA USA
|
 |
« Reply #7 on: December 27, 2012, 09:11:25 pm » |
Do I need the what? Probably not.
|
|
|
|
|
Logged
|
|
|
|
|
|