#include <ShiftRegister74HC595.h>
ShiftRegister74HC595<1> sr(8, 10, 9);
// const int dataPin = 8; // Pin 14 on the shift register
// const int latchPin = 9; // Pin 12 on the shift register
// const int clockPin = 10; // Pin 11 on the shift register
void setup() {
Serial.begin(115200);
// pinMode(dataPin, OUTPUT);
// pinMode(latchPin, OUTPUT);
// pinMode(clockPin, OUTPUT);
}
void loop(){
// digitalWrite(latchPin, LOW);
// digitalWrite(latchPin, HIGH);
// delayMicroseconds(10);
// for(int i=0; i<8; i++){
// digitalWrite(clockPin, LOW);
// int switchState = digitalRead(dataPin);
// Serial.println("Switch " + String(i) + " state: " + String(switchState));
// digitalWrite(clockPin, HIGH);
// delayMicroseconds(10);
// };
// delay(1000);
sr.setAllHigh(); // set all pins HIGH
delay(500);
sr.setAllLow(); // set all pins LOW
delay(500);
for (int i = 0; i < 8; i++) {
sr.set(i, HIGH); // set single pin HIGH
delay(250);
}
// set all pins at once
uint8_t pinValues[] = { B10101010 };
sr.setAll(pinValues);
delay(1000);
// read pin (zero based, i.e. 6th pin)
uint8_t stateOfPin5 = sr.get(5);
sr.set(6, stateOfPin5);
// set pins without immediate update
sr.setNoUpdate(0, HIGH);
sr.setNoUpdate(1, LOW);
// at this point of time, pin 0 and 1 did not change yet
sr.updateRegisters(); // update the pins to the set values
};