The keys do nothing or they don't correspond to the symbols on the buttons - etc
I tried connecting it as it said in the description - didn't work
I tried using it with the Keypad.h examples and with my program - which worked with another Keypad - but not with this one
My code turns on an LED and sends a signal depending on if the code is accepted or not
It displays asterisks and beeps for every input
Right now its configured for a 3 character code "123"
Here is my code:
Code: Select all
//import libraries
#include <Password.h>
#include <Keypad.h>
#include <LiquidCrystal.h>
#define GreenStrip 9//green LED's
#define RedStrip 10//red LED's
#define buzzerPin 11//buzzer
#define accepted 12//accepted signal to PLC
#define declined 13//declined signal to PLC
//relay values
#define RELAY_ON 1
#define RELAY_OFF 0
Password password = Password("123"); // password
int dlugosc = 3; // length of the password
LiquidCrystal lcd(22, 23, 24, 25, 26, 27);//(RS, E, D4, D5, D6, D7)
int ilosc;//number of clicks
const byte ROWS = 4; // rows
const byte COLS = 3; // cols
char keys[ROWS][COLS] =
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {2,3,4,5};
byte colPins[COLS] = {6,7,8};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
Serial.begin(9600);//begin serial
keypad.addEventListener(keypadEvent);//add keypad
//outputs
pinMode(GreenStrip, OUTPUT);
pinMode(RedStrip, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(accepted, OUTPUT);
pinMode(declined, OUTPUT);
//default states
digitalWrite(GreenStrip, RELAY_OFF);
digitalWrite(RedStrip, RELAY_OFF);
noTone(buzzerPin);
digitalWrite(accepted, RELAY_OFF);
digitalWrite(declined, RELAY_OFF);
lcd.begin(16, 1);//initialize LCD
lcd.clear();
lcd.print(" ENTER CODE ");
}
void loop() {
keypad.getKey();//run main method
}
void keypadEvent(KeypadEvent eKey) {
switch (keypad.getState()) {
case PRESSED://if key is pressed beep
for(int i = 1; i <= 1; i++ ) {
tone(buzzerPin, HIGH);
delay(50);
noTone(buzzerPin);
delay(50);
}
Serial.print("Pressed: ");
Serial.println(eKey);
switch (eKey) {
case '#':
break;
case '*':
break;
default:
ilosc=ilosc+1;
password.append(eKey);
}
//print statements
if(ilosc == 1) {
lcd.clear();
lcd.print("*_");
}
if(ilosc == 2) {
lcd.clear();
lcd.print("**_");
}
if(ilosc == 3) {
lcd.clear();
lcd.print("***_");
}
if(ilosc == 4) {
lcd.clear();
lcd.print("****_");
}
if(ilosc == 5) {
lcd.clear();
lcd.print("*****_");
}
if(ilosc == 6) {
lcd.clear();
lcd.print("******_");
}
if(ilosc == 7) {
lcd.clear();
lcd.print("*******_");
}
if(ilosc == 8) {
lcd.clear();
lcd.print("********_");
}
if(ilosc == 9) {
lcd.clear();
lcd.print("*********_");
}
if(ilosc == 10) {
lcd.clear();
lcd.print("**********_");
}
if(ilosc == 11) {
lcd.clear();
lcd.print("***********_");
}
if(ilosc == 12) {
lcd.clear();
lcd.print("************_");
}
if(ilosc == 13) {
lcd.clear();
lcd.print("*************_");
}
if(ilosc == 14) {
lcd.clear();
lcd.print("**************_");
}
if(ilosc == 15) {
lcd.clear();
lcd.print("***************");
}
//if number of entered keys equas passwords length check password
if(ilosc == dlugosc) {
delay(250);
checkPassword();
ilosc = 0;
}
}
}
void checkPassword() {
if (password.evaluate()) {//if password is correct
digitalWrite(RedStrip, RELAY_OFF);//make sure red strip is off
for(int i = 1; i <= 2; i++ ) {//beep and blink
tone(buzzerPin, 255);
digitalWrite(GreenStrip, RELAY_ON);
delay(100);
digitalWrite(GreenStrip, RELAY_OFF);
noTone(buzzerPin);
delay(100);
}
ilosc = 0;//reset
//send signal to PLC
digitalWrite(accepted, RELAY_ON);
delay(100);
digitalWrite(accepted, RELAY_OFF);
//print message
lcd.clear();
lcd.print(" ACCEPTED ");
delay(150);
}
else {//if its not correct
digitalWrite(GreenStrip, RELAY_OFF);//make sure green strip is off
//reset
ilosc = 0;
password.reset();
//send message to PLC
digitalWrite(declined, RELAY_ON);
delay(100);
digitalWrite(declined, RELAY_OFF);
//turn red strip on until penalty runs and PWR shuts keypad off
digitalWrite(RedStrip, RELAY_ON);
//print message
lcd.clear();
lcd.print(" DENIED ");
delay(150);
}
}
Maybe its defective?
Thanks!