https://medium.com/@tiemenwaterreus/driving-16-leds-using-only-three-pins-of-an-arduino-3a6b1f60bc2c
My Schematic is like above
Hi , this program work fine to one register 74HC595, How can I control two 74HC595 inside this?
const int latchPin = 27;
const int clockPin = 14;
const int dataPin = 23;
int i = 25;
byte leds = 0;
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
Serial.begin(115200);
Serial.println(“setup”);
}
void loop() {
if (Serial.available() > 0) {
int inByte = Serial.read();
switch (inByte) {
case ‘a’:
i = 0;
break;
case ‘b’:
i = 1;
break;
case ‘h’:
i = 7;
break;
case ‘j’:
i = 9;
break;
case ‘L’:
i = 10;
break;
default:
i = 25;
}
}
if ( i == 9) {
bitSet(leds, 0);
bitSet(leds, 1);
bitSet(leds, 2);
bitSet(leds, 3);
bitSet(leds, 4);
bitSet(leds, 5);
bitSet(leds, 6);
bitSet(leds, 7);
bitSet(leds, 8);
updateShiftRegister();
}
if ( i == 10) {
bitClear(leds, 0);
bitClear(leds, 1);
bitClear(leds, 2);
bitClear(leds, 3);
bitClear(leds, 4);
bitClear(leds, 5);
bitClear(leds, 6);
bitClear(leds, 7);
bitClear(leds, 8);
updateShiftRegister();
}
if ( i == 0) {
bitSet(leds, 0);
updateShiftRegister();
Serial.println(“0 on”);
}
if ( i == 1) {
bitSet(leds, 1);
updateShiftRegister();
Serial.println(“1 on”);
}
if ( i == 7) {
bitSet(leds, 7);
updateShiftRegister();
Serial.println(“7 on”);
}
}
Hi.
I think this tutorial covers what you are looking for: https://www.arduino.cc/en/Tutorial/Foundations/ShiftOut
Let me know if you need further help.
Regards,
Sara