#define CLK 3
#define SER 4
#define LATCH 2
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(CLK, OUTPUT);
pinMode(SER, INPUT);
pinMode(LATCH, OUTPUT);
}
int switches[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void loadData() {
// latch the data in
digitalWrite(LATCH, LOW);
digitalWrite(LATCH, HIGH);
// then send a clock pulse and read what is on the data line
for(int i = 0; i < 16; i++) {
switches[15-i] = digitalRead(SER);
digitalWrite(CLK, HIGH);
digitalWrite(CLK, LOW);
Serial.print(switches[i]);
}
Serial.println();
// then unlatch the register
digitalWrite(LATCH, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
loadData();
delay(10);
}