I recently saw a guy using 74HC595 shift registers for input rather than output and couldn't understand how the hell he did that. He also was sending only 4 wires to his Arduino (for 5v, GND, Serial and Clock.....no Latch)....and it worked? How did this happen?
Has anybody here done that before?
Here is his code that does the shifting but I don't really understand it...(i know there are some other parts which this code refers to and if u want to see it I can post more but this was the part I was having trouble understanding)
//This is the meat of the code. It shifts bits down the shift registers until a signal is received back at the KEYpin, which tells it what key has been pressed.
byte waitForKeystroke(){
byte key = 0;
byte doublecheckkey = 0;
unsigned int keypress_count = 0;
//LOOP UNTIL A KEY IS PRESSED
while(key == 0){
if(waitcount<30000){
waitcount++;
}
digitalWrite(SERpin,HIGH);
pulseHigh(RCLKpin);
digitalWrite(SERpin,LOW);
// 1500 nanoseconds = 1.5 uS = probably used because old Arduino delayMicroseconds used to disable interrupts
asm("nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;");
asm("nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;");
for (int shift_i = 1; shift_i<95;shift_i++) {
pulseHigh(RCLKpin);
if (digitalRead(KEYpin) == HIGH){
key = shift_i;
}
}
if(digitalRead(7) != polarity7) {key = 96;}
if(digitalRead(8) != polarity8) {key = 97;}
if(digitalRead(9) != polarity9) {key = 98;}
if(digitalRead(10) != polarity10) {key = 99;}
//if(digitalRead(TEACHpin) == 0){key = 96;}//teachpin used as general input for modvic
} // END OF WHILE LOOP
// DOUBLE-CHECK:
digitalWrite(SERpin,HIGH);
pulseHigh(RCLKpin);
digitalWrite(SERpin,LOW);
asm("nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;");
asm("nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;");
for (int shift_i = 1; shift_i<95;shift_i++){
pulseHigh(RCLKpin);
if (digitalRead(KEYpin) == HIGH){
doublecheckkey = shift_i;
}
}
if(doublecheckkey != key) {key = INVALID;}
if(digitalRead(7) != polarity7) {key = 96;} // commented out for modvic
if(digitalRead(8) != polarity8) {key = 97;}
if(digitalRead(9) != polarity9) {key = 98;}
if(digitalRead(10) != polarity10) {key = 99;}
// if(digitalRead(TEACHpin) == 0) {key = 96;} //teachpin used as general input for modvic
return key;
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.