using three shift registers to control 24 leds via only 3 pins on the arduino
code:
int dataPin = 11;
int latchPin = 8;
int clockPin = 12;
void setup() {
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
long unsigned bin=1;
for (int tensColumn = 1; tensColumn < 25; tensColumn++) {
// 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, bin);
// shiftOut(dataPin, clockPin, MSBFIRST, bin>>8);
shiftOut(dataPin, clockPin, MSBFIRST, bin);
shiftOut(dataPin, clockPin, MSBFIRST,bin>>8);
shiftOut(dataPin, clockPin, MSBFIRST,bin>>16);
bin*=2; // 1 becomes 10 , becomes 100 , becomes 1000 and so on in binary
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
// pause before next value:
delay(30);
}
bin=8388608;// 1000000000000000000000000 in binary
for (int tensColumn = 1; tensColumn < 25; tensColumn++) {
// 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, bin);
shiftOut(dataPin, clockPin, MSBFIRST, bin>>8);
shiftOut(dataPin, clockPin, MSBFIRST, bin>>16);
bin/=2;
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
// pause before next value:
delay(30);
}
}