Page 2 of 2

Re: Reading a Keypad

PostPosted: Sat Nov 05, 2011 2:15 pm
by low5545
OK, now I am starting to know how the keypad scanning works. I've done a experiment with my Arduino Uno on a self-made 2x1 tactile switch keypad (2 columns and 1 row) And the sketch works like this:
CODE: SELECT_ALL_CODE
int col1=6;
int col2=7;
int row=8;
int stat1;
int stat2;
int val;

void setup(){
  pinMode(col1,INPUT);
  pinMode(col2,INPUT);
  pinMode(row,OUTPUT);
  Serial.begin(9600);
}

void loop(){
  stat1=digitalRead(col1);
  stat2=digitalRead(col2);
  digitalWrite(row,HIGH);
  val++;
  digitalWrite(row,LOW);
  val--;
  if(stat1==LOW && val==0){
    Serial.println("1");
  }
  else if(stat2==LOW && val==0){
    Serial.println("2");
  }
  else{
    Serial.println("Please key in the password");
    delay(10);
  }
}
 


And finally it works! Any more suggestions on the code? The val+- thing may not be useful for this example, but I want it to works on other 4x4 keypads later.