// Pin ST_CP of HC595,
// we will be using this pin
// to control led status
// using digitalWrite(latchPin, ledstatus);
int latchPin = 12;
// Pin SH_CP of HC595
int clockPin = 11;
// Pin DS of HC595
int dataPin = 13;
const int HC595_count = 2; // Number of HC595
byte ledStatus[HC595_count] = {0}; // Array of led status
int i, j; // Variables to use in for loop
void setup() {
// put your setup code here, to run once:
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void fillValueToLed(byte value){
for (i = 0; i < HC595_count; i++){
ledStatus[i] = value;
}
}
void shiftOut_inShorten(){
digitalWrite(latchPin, LOW);
for (i = 0; i < HC595_count; i++){
shiftOut(dataPin, clockPin, MSBFIRST, ledStatus[i]);
}
digitalWrite(latchPin, HIGH);
delay(1000);
};
void loop() {
// put your main code here, to run repeatedly:
//Using MSBFIRST - the light turn in correct order
//Using LSBFIRST - the light turn in reverse order
fillValueToLed(0b10101010);
shiftOut_inShorten();
fillValueToLed(0b01010101);
shiftOut_inShorten();
}