0
Offline
Jr. Member
Karma: 0
Posts: 86
Arduino rocks
|
 |
« on: October 21, 2009, 06:19:50 pm » |
Hi... I chained 2 shift registers with a bank of leds to attached each and successfully had them light up one at a time. Great.
Now I want to scale up.
I added another shift register and 8 more leds...
I have not been able to modify the following program (which I got off the internet and modified) to correctly light up the leds from 0 to 24 or 32 or 40... I want to understand how to modify the program so that I can chain any number of shift registers and be able to light up the full string or any individual led...
I would very much appreciate the help!!!!
Here it is:
// chain multiple shift registers, each with 8 leds // light 1 led at a time, from 1 to 24 - blanking out each previous lit led // then start again // //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() { pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); digitalWrite(latchPin, 0); //make sure data isn't latched } void loop() { unsigned int outputpattern =1; //stores the output pattern as an unsigned int, that is, two bytes int pattern_LSB; //the least significant byte (LSB) of the pattern int pattern_MSB; //the most significant byte (MSB) of the pattern for (int i=0 ; i< 16; i++){ pattern_MSB = outputpattern >>8; //extract the MSB of the pattern by shifting all the bits over by 8 pattern_LSB = outputpattern & B11111111; //extract the LSB of the pattern by bitwise AND shiftOut(dataPin, clockPin, MSBFIRST, (byte) pattern_MSB); shiftOut(dataPin, clockPin, MSBFIRST, (byte) pattern_LSB); digitalWrite(latchPin, 1); // flick the latch to put the data on the output pins delay(1);
digitalWrite(latchPin, 0); delay(100);
outputpattern = outputpattern <<1; // shift the outputpattern left by one bit
} }
|