Skip to content

Instantly share code, notes, and snippets.

@Ultrawipf
Created July 26, 2022 18:31
Show Gist options
  • Save Ultrawipf/2ef267a60a94552940aac5ae5eae70fa to your computer and use it in GitHub Desktop.
Save Ultrawipf/2ef267a60a94552940aac5ae5eae70fa to your computer and use it in GitHub Desktop.
74HC165 PISO shift register example for Arduino
#define CSPIN 2
#define CLKPIN 3
#define DPIN 4
void setup() {
pinMode(CSPIN, OUTPUT);
pinMode(CLKPIN, OUTPUT);
pinMode(DPIN, INPUT);
Serial.begin(115200);
}
void loop() {
int buf[4];
digitalWrite(CLKPIN, HIGH); // Make sure clock is high so first transition is "skipped"
digitalWrite(CSPIN,HIGH); // Latch
// Set clock enable low here if used
Serial.println("Data:");
for(int i = 0;i<4;i++){
buf[i] = shiftIn(DPIN,CLKPIN,LSBFIRST ); // Shift 1 byte in
Serial.println(buf[i],BIN);
}
digitalWrite(CSPIN,LOW); // Latch low
digitalWrite(CLKPIN, LOW);
// Set clock enable high here if used
Serial.print('\n');
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment