Create a gist now

Instantly share code, notes, and snippets.

anonymous /shiftin_out.ino
Created May 2, 2014

Shift In - Shift Out
int latchPin = 8; // Pin connected to ST_CP of 74HC595
int dataPin = 9; // Pin connected to DS of 74HC595
int clockPin = 10; // Pin connected to SH_CP of 74HC595
int sinPin = 5; // Serial input pin from 74HC165
int sclkPin = 6; // Clock pin to '165
int loadPin = 7; // parallel load pin of '165
void setup() {
Serial.begin(9600);
//set pins to input/output so you can control the shift registers
pinMode(loadPin, OUTPUT);
pinMode(sclkPin, OUTPUT);
pinMode(sinPin, INPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
digitalWrite(sclkPin,HIGH); // initialise the clock HIGH
}
void loop() {
while(1){
// Read incoming word from 74HC165
digitalWrite(loadPin, LOW);
digitalWrite(loadPin, HIGH);
int incoming = shiftIn(sinPin, sclkPin, MSBFIRST);
digitalWrite(sclkPin,HIGH);
// and write it out to 74HC595
PORTB &= ~_BV(0);
shiftOut(dataPin, clockPin, MSBFIRST, incoming); // shift out the bits:
PORTB |= _BV(0);
Serial.println(incoming); // just some debug
// delay(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment