So this example code:
const int latchPin = 8;
const int clockPin = 12;
const int dataPin = 11;
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);
}
void loop() {
// iterate over the 16 outputs of the two shift registers
for (int thisLed = 0; thisLed < 16; thisLed++) {
// write data to the shift registers:
registerWrite(thisLed, LOW);
// if this is not the first LED, turn off the previous LED:
if (thisLed >= 0) {
registerWrite(thisLed - 1, HIGH);
}
// if this is the first LED, turn off the highest LED:
else {
registerWrite(15, HIGH);
}
// pause between LEDs:
delay(130);
}
for (int thisLed = 16; thisLed > 0; thisLed--) {
registerWrite(thisLed, LOW);
if (thisLed >= 0) {
registerWrite(thisLed - 1, HIGH);
}
else {
registerWrite(15, HIGH);
}
delay(130);
}
}
// This method sends bits to the shift registers:
void registerWrite(int whichPin, int whichState) {
// 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);
// break the bits into two bytes, one for
// the first register and one for the second:
byte registerOne = highByte(bitsToSend);
byte registerTwo = lowByte(bitsToSend);
// shift the bytes out:
shiftOut(dataPin, clockPin, MSBFIRST, registerTwo);
shiftOut(dataPin, clockPin, MSBFIRST, registerOne);
// turn on the output so the LEDs can light up:
digitalWrite(latchPin, HIGH);
}
let me shift out the code to 2 registers. I tried using
byte registerThree = highByte(bitsToSend);
under
byte registerOne = highByte(bitsToSend);
byte registerTwo = lowByte(bitsToSend);
so it can shift out a third bit but it doesn't work. I am trying to shift out the code the a third register. which part should i modify??
thanks