74HC595 used for shift input not output!

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.

Its easy he is reading a keypad where you set just one columns high and scan the rows for a press.
Or set one row high and scan the columns which ever way you want to do it.
But he is not reading it as a input.

I recently saw a guy using 74HC595 shift registers for input rather than output

No you did not. You misunderstood.
Read the how to use this forum sticky post. Look at your code, is it how you posted it?

I think you probably not talking about this guy.

Take a look at his video and his follow up video:

Both greats, and you will fully understand this and how it's done. I think it's ok for "playing" but... I read this comment on his videos

Why didn't you used a? parallel-in serial-out shift register,? like the 74165?

...so, for playing around its ok, otherwise you can get those type of Shift Registers for the job.

1 Like

any idea how he was only using 4 wires to the microcontroller? (5v, GND, Ser, Clk)

thanks for the help so far

He is pulling the latch to ground. It's in the datasheet outputs active when E pin is low so you tie it low and just use the data and the clock