Skip to content

Instantly share code, notes, and snippets.

@keshavsaharia
Created December 15, 2013 19:56
Show Gist options
  • Save keshavsaharia/7977356 to your computer and use it in GitHub Desktop.
Save keshavsaharia/7977356 to your computer and use it in GitHub Desktop.
4x4 keypad matrix for Arduino
int getKey() {
int A = 2;
while (A <= 5) {
pinMode(A, OUTPUT);
digitalWrite(A, HIGH);
int B = 6;
while (B <= 9) {
pinMode(B, OUTPUT);
pinMode(B, INPUT);
if (digitalRead(B) == HIGH) {
return (A - 2) * 4 + (B - 5);
}
}
digitalWrite(A, LOW);
A = A + 1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment