/*
74HC595 Pins:
Pin 14 (DS) -> Arduino pin 11 (Data)
Pin 11 (SH_CP) -> Arduino pin 12 (Clock)
Pin 12 (ST_CP) -> Arduino pin 8 (Latch)
Pin 10 (MR) -> 5V (Master Reset, active low, so we connect it to 5V to disable reset)
Pin 13 (OE) -> GND (Output Enable, active low, so we connect it to GND to enable outputs)
Pin 16 (VCC) -> 5V
Pin 8 (GND) -> GND
RGB LED Connections:
Connect the anodes (long leg) of the RGB LEDs to a current-limiting resistor (typically 220 ohms) and then to 5V.
Connect the cathodes (R, G, B legs) of the RGB LEDs to the output pins of the 74HC595 shift register. For example:
Q0 -> Red of LED1
Q1 -> Green of LED1
Q2 -> Blue of LED1
Q3 -> Red of LED2
Q4 -> Green of LED2
Q5 -> Blue of LED2
*/
// Define connections to 74HC595
#define DATA_PIN1 13 // DS
#define CLOCK_PIN1 11 // SH_CP
#define LATCH_PIN1 12 // ST_CP
#define DATA_PIN2 10 // DS
#define CLOCK_PIN2 8 // SH_CP
#define LATCH_PIN2 9 // ST_CP
const byte color1[]{
B00000001,
B00000010,
B00000100,
B00000011,
B00000101,
B00000110
};
const byte color2[]{
B00001000,
B00010000,
B00100000,
B00011000,
B00101000,
B00110000
};
const byte color3[]{
B00000001,
B00000010,
B00000100,
B00000011,
B00000101,
B00000110
};
const byte color4[]{
B00001000,
B00010000,
B00100000,
B00011000,
B00101000,
B00110000
};
void setup() {
// Set pin modes
pinMode(DATA_PIN1, OUTPUT);
pinMode(CLOCK_PIN1, OUTPUT);
pinMode(LATCH_PIN1, OUTPUT);
pinMode(DATA_PIN2, OUTPUT);
pinMode(CLOCK_PIN2, OUTPUT);
pinMode(LATCH_PIN2, OUTPUT);
}
void loop() {
for (int i = 0; i < 6; i++) {
byte color = color1[i] | color2[i];
updateShiftRegister (color);
delay(500);
}
for (int i = 0; i < 2; i++) {
byte color = color3[i] | color4[i];
updateShiftRegister (color);
delay(500);
}
}
void updateShiftRegister(byte color) {
digitalWrite(LATCH_PIN1, LOW);
shiftOut(DATA_PIN1, CLOCK_PIN1, MSBFIRST, color);
digitalWrite(LATCH_PIN1, HIGH);
digitalWrite(LATCH_PIN2, LOW);
shiftOut(DATA_PIN2, CLOCK_PIN2, MSBFIRST, color);
digitalWrite(LATCH_PIN2, HIGH);
}