Reading a Keypad

FYP Starter Pack, ICs, Voltage Regulator, Resistor, Capacitor......

Re: Reading a Keypad

Postby low5545 » Sat Nov 05, 2011 2:15 pm

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.
low5545
Discoverer
 
Posts: 70
Joined: Wed Jul 27, 2011 5:55 pm
Location: Kuala Lumpur

Previous

Return to Electronic Component

Who is online

Users browsing this forum: No registered users and 3 guests

cron