I'm using an arduino uno and a 3x4 keypad. My question is how can I input multiple keypresses so that it creates passcode to turn on an led. Example I want my passcode to be "1234", and inputing this passcode turns on the led.
The code I'm using now works so that I can press one digit and it will turn on the led.
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6, A0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {13, 10, 9}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int led=A1;
void setup(){
Serial.begin(9600);
pinMode(led, OUTPUT);
}
void loop(){
char key = keypad.getKey();
digitalRead(key);
switch(key){
case '1':
digitalWrite(led,HIGH);
delay(5000);
break;
default:
digitalWrite(led,LOW);
}
if (key){
Serial.println(key);
}
}