Go Down

Topic: 3 Shift Registers (Read 1 time) previous topic - next topic

hotstyle765

I am trying to chain up 3 shift registers. I am pretty sure my wiring is all set but I am having issues with the code.

I am using the shift out example and changing it for a third shift register.

The problem is I am not seeing any LEDs light up on the third register after my changes.

I am guessing it has to do with this line:
Code: [Select]
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend >> 16);

Is that not supposed to be 16 for the third register?
(You can ignore the comments as I have not changed them from the example.
Thanks in advance for the help!

Here is the rest of the code...
Code: [Select]
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
////Pin connected to DS of 74HC595
int dataPin = 9;
//Pin connected to SH_CP of 74HC595
int clockPin = 10;



/*
 Shift Register Example
for two 74HC595 shift registers

This sketch turns on each of the LEDs attached to two 74HC595 shift registers,
in sequence from output 0 to output 15.

Hardware:
* 2 74HC595 shift register attached to pins 2, 3, and 4 of the Arduino,
as detailed below.
* LEDs attached to each of the outputs of the shift register

Created 22 May 2009
Modified 23 Mar 2010
by Tom Igoe

*/

char inputString[2];

void setup() {
 //set pins to output because they are addressed in the main loop
 pinMode(latchPin, OUTPUT);
 pinMode(dataPin, OUTPUT);  
 pinMode(clockPin, OUTPUT);
 Serial.begin(9600);
 Serial.println("reset");
}

void loop() {
 // iterate over the 16 outputs of the two shift registers
 for (int thisLed = 0; thisLed < 24; thisLed++) {
   // write data to the shift registers:
   registerWrite(thisLed, HIGH);
   // if this is not the first LED, turn off the previous LED:
   if (thisLed > 0) {
     registerWrite(thisLed - 1, LOW);
   }
   // if this is  the first LED, turn off the highest LED:
   else {
     registerWrite(24, LOW);
   }
   // pause between LEDs:
   
 }

}

// This method sends bits to the shift registers:

void registerWrite(int whichPin, int whichState) {
 delay(500);
 // the bits you want to send. Use an unsigned int,
 // so you can use all 16 bits:
 unsigned int bitsToSend = 0;    

 // turn off the output so the pins don't light up
 // while you're shifting bits:
 digitalWrite(latchPin, LOW);

 // turn on the next highest bit in bitsToSend:
 bitWrite(bitsToSend, whichPin, whichState);

 // shift the bytes out:
 shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend >> 16);
 shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend >> 8);
 shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);

 // turn on the output so the LEDs can light up:
 digitalWrite(latchPin, HIGH);
}


hotstyle765

Duh....

 // so you can use all 16 bits:
 unsigned int bitsToSend = 0;

changed to unsigned long and I am all set.

Go Up