Created
May 2, 2014 15:22
-
-
Save anonymous/99fc75ff4b4cf0c48c93 to your computer and use it in GitHub Desktop.
Shift In - Shift Out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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