/*
* 74HC165
* SH/LD 2
* CLK 3
* QH 4
*/
int const SL = 13; //Data SH/LD
int const CLK = 12; //Clock CLK
int const SER = 11; //Latch QH
int incomingData;
int incomingDataOld;
byte myShiftIn(int dataPin, int clockPin, int loadPin){
byte data;
digitalWrite(loadPin, LOW); //A-Hを格納
digitalWrite(loadPin, HIGH); //確定
data = digitalRead(dataPin); //Hの値を読む
for (int i=1; i<8; i++){
digitalWrite(clockPin, HIGH);
data = data << 1 | (digitalRead(dataPin)); //G,F,E...Aの値を読む
digitalWrite(clockPin, LOW);
}
return data;
}
void setup() {
pinMode(CLK, OUTPUT);
pinMode(SL, OUTPUT);
pinMode(SER, INPUT);
digitalWrite(SL, HIGH);
digitalWrite(CLK, LOW);
Serial.begin(9600);
}
void loop() {
incomingData = myShiftIn(SER, CLK, SL);
if (incomingData != incomingDataOld){
Serial.println(incomingData, BIN);
}
incomingDataOld = incomingData;
}