I need to control approx 40 pairs of bi-color LEDs. 10 to start with, adding more over time for a total of 40 pairs (80 bi-color LEDS in total). About 80% of the pairs will be ON at any given time so I think I need to power them from an external power supply.
The LEDs act as indicators and are spread out on a panel and not in any physical row/column matrix.
All LEDs are 2 pin bi-color, draw 20mA each, and need to be controlled as sets of pairs with 3 states per pair.
State 1 - both OFF
State 2 - first LED is ON, showing Red, second in pair is ON showing Green
State 3 - first LED is ON, showing Green, second in pair is ON showing Red
The LED pair's state is dependent upon multiple sensors providing input via 74HC165 shift register and also input to the nano is keyed into a connected PC.
An input is expected on average of 2 secs requiring the display to be updated 2 secs average.
I have successfully connected 1 pair via shift register as proof of concept where each LED is connected to 2 outputs from shift register(74HC595). A set of 4 register outputs work as a pair, both low, high/low or low/high to match the 3 states.
Diagram and test piece of code is attached.
Question : Not sure if this is the best way to design this circuit. If I were to supply power to the LEDs could I use a transistor between the shift register and the LED, and if so how should I put the circuit together please?
Any help would be greatly appreciated.
#define Q14_Data 4
#define Q12_Latch 5
#define Q11_Register_Clock 6
void setup()
{
pinMode(Q14_Data, OUTPUT);
pinMode(Q12_Latch, OUTPUT);
pinMode(Q11_Register_Clock, OUTPUT);
digitalWrite(Q12_Latch, LOW);
// set all LEDS OFF
shiftOut(Q14_Data, Q11_Register_Clock, LSBFIRST, 0);
digitalWrite(Q12_Latch, HIGH);
}
void loop()
{
// Test code to validate one pair of LED's
digitalWrite(Q12_Latch, LOW);
shiftOut(Q14_Data, Q11_Register_Clock, LSBFIRST, 0b10010000);
digitalWrite(Q12_Latch, HIGH);
delay(1000);
digitalWrite(Q12_Latch, LOW);
shiftOut(Q14_Data, Q11_Register_Clock, LSBFIRST, 0b01100000);
digitalWrite(Q12_Latch, HIGH);
delay(5000);
}