Ok, Another problem. I am building a keypad door lock, and all the other parts work. I have LEDs to print when the codeis right or wrong. But for some reason, it keeps returning the red LED, even when the code is correct! Please help me. code:
#include <Keypad.h>
char pass[3] = "";
const int led1=12;
const int led2=10;
const int led3=11;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void strcat(char* original, char appended)
{
while (*original++)
;
*original++ = appended;
if (appended)
*original = '\0';
}
void setup(){
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
delay(2000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey){
strcat(pass, customKey);
Serial.println(customKey);
if(customKey=='#'){
if(pass[3]==['2', '1', '2']){
Serial.println(pass);
char pass[3]="";
digitalWrite(led3, HIGH);
delay(10000);
digitalWrite(led3, LOW);
}
else{
Serial.println(pass);
char pass[3]="";
digitalWrite(led1, HIGH);
delay(2000);
digitalWrite(led1, LOW);
}
}
}
}
I am a noob, so i need lots of help.
thanks.