int latchPinRed = 5; // Latch pin of 74HC595 is connected to Digital pin 5
int clockPinRed = 6; // Clock pin of 74HC595 is connected to Digital pin 6
int dataPinRed = 4; // Data pin of 74HC595 is connected to Digital pin 4
int latchPinGreen = 9; // Latch pin of 74HC595 is connected to Digital pin 5
int clockPinGreen = 10; // Clock pin of 74HC595 is connected to Digital pin 6
int dataPinGreen = 8;
byte ledsRed = 0;// Variable to hold the pattern of which LEDs are currently turned on or off
byte ledsGreen =0;
int pb = 2;
int a =0;
/*
* setup() - this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
void setup()
{
// Set all the pins of 74HC595 as OUTPUT
pinMode(latchPinRed, OUTPUT);
pinMode(dataPinRed, OUTPUT);
pinMode(clockPinRed, OUTPUT);
pinMode(latchPinGreen, OUTPUT);
pinMode(dataPinGreen, OUTPUT);
pinMode(clockPinGreen, OUTPUT);
pinMode(pb, INPUT_PULLUP);
}
void loop()
{
a = digitalRead(pb);
if (a == LOW){
bitSet(ledsRed, 0);
updateShiftRegister();
}else{
bitClear(ledsRed, 0);
updateShiftRegister();
}
}
void updateShiftRegister()
{
digitalWrite(latchPinRed, LOW);
shiftOut(dataPinRed, clockPinRed, MSBFIRST, ledsRed);
digitalWrite(latchPinRed, HIGH);
digitalWrite(latchPinGreen, LOW);
shiftOut(dataPinGreen, clockPinGreen, MSBFIRST, ledsGreen);
digitalWrite(latchPinGreen, HIGH);
}