//74hc595 uscite
int clockPin = 8;
int latchPin = 9;
int dataPin = 10;
// 74hc165 ingressi
#define REG_SL 2
#define REG_CK 3
#define REG_DI 5
byte n=0;
byte x=0;
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(REG_SL, OUTPUT);
pinMode(REG_CK, OUTPUT);
pinMode(REG_DI, INPUT);
Serial.begin(9600);
}
void loop() {
//acquisizione porte d'ingresso
digitalWrite(REG_SL, HIGH);
delay(1);
digitalWrite(REG_SL, LOW);
delay(1);
digitalWrite(REG_SL, HIGH);
for (int i = 0; i < 8 ; i++) {
bitWrite(n, i, digitalRead(REG_DI));
digitalWrite(REG_CK, LOW);
delay(1);
digitalWrite(REG_CK, HIGH);
delay(1);
}
for (int i = 0; i < 8 ; i++) {
bitWrite(x, i, digitalRead(REG_DI));
digitalWrite(REG_CK, LOW);
delay(1);
digitalWrite(REG_CK, HIGH);
delay(1);
}
Serial.print(n, BIN);
Serial.println(x, BIN);
// trasmissione byte porte uscite
//for (int i = 0; i < 8 ; i++) {
// bitWrite(x,7-i,bitRead(n, i));
//}
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, x);
shiftOut(dataPin, clockPin, LSBFIRST, n);
digitalWrite(latchPin, HIGH);
delay(1);
}