One wire keypad by Analog pin

I am creating a program for Arduino Uno. However, the code does not work. I tried to piece together the code from various instructions. I am a complete beginner. Please, give me an advice.

password = "12345 or 123A589 or 1593574682... etc.) // password entered by the user with any number of characters. But at least 4 characters

Serial.begin(9600);//Display the values and keys used on the serial monitor.

LiquidCrystal_I2C lcd(0x27, 16, 2);

Used 4x4 keyboard
Pin A0 with ranges is used to read values.
use in code.

if (value >= 66 - 2 && value <= 66 + 2) pressed = '1';
else if (value >= 255 - 2 && value <= 255 + 2) pressed = '2';// And other values

The task of the program will be to control the servo (open, close) using a password.
When servo position - open .LCD display says "Open, close with #". //When servo position - open, press # to perform position - close.
If the position of the servo is - closed - Its writing on the LCD "Enter code, card (position 0,0) , "Code:------------" (LCD position 0,1). / To open a password must be used.

Ukázka kódu
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
Servo servo;
LiquidCrystal_I2C lcd(0x27, 16, 2); // address, columns, rows
int openPos = 45;
int closedPos = 135;
String password = "11111"; // user-entered password
bool isOpen = false; // keep track of servo position
bool isEnteringPassword = false; // keep track of user input state
String enteredPassword = ""; // keep track of entered password
void setup() {
Serial.begin(9600);
servo.attach(3);
servo.write(closedPos);
lcd.begin(16, 2);
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter code");
lcd.setCursor(0, 1);
lcd.print("Code:------------");
}
void checkPassword(char key) {
if (isEnteringPassword) {
if (key == '#') {
if (enteredPassword.length() >= 4 && enteredPassword == password) {
isEnteringPassword = false;
enteredPassword = "";
lcd.clear();
if (isOpen) {
servo.write(closedPos);
isOpen = false;
lcd.setCursor(0, 0);
lcd.print("Closed");
} else {
servo.write(openPos);
isOpen = true;
lcd.setCursor(0, 0);
lcd.print("Open, close #");
}
} else {
enteredPassword = "";
lcd.setCursor(0, 1);
lcd.print("Code:------------");
lcd.setCursor(6, 0);
lcd.print("Incorrect");
}
} else if (key == '') {
enteredPassword = "";
isEnteringPassword = false;
lcd.clear();
lcd.setCursor(0, 0);
if (isOpen) {
lcd.print("Open, close #");
} else {
lcd.print("Enter code, card");
lcd.setCursor(0, 1);
lcd.print("Code:------------");
}
} else if (enteredPassword.length() < password.length()) {
enteredPassword += key;
lcd.setCursor(5 + enteredPassword.length(), 1);
lcd.print(key);
}
} else {
if (key == '
') {
isEnteringPassword = true;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter password");
lcd.setCursor(0, 1);
lcd.print("Code:------------");
} else {
lcd.setCursor(0, 0);
if (isOpen) {
lcd.print("Open, close #");
} else {
lcd.print("Enter code, card");
lcd.setCursor(0, 1);
lcd.print("Code:------------");
}
}
}
}
void loop() {
int val = analogRead(A0);
if (val >= 66 - 2 && val <= 66 + 2) {
char key = '1';
checkPassword(key);
}
else if (val >= 255 - 2 && val <= 255 + 2) {
char key = '2';
checkPassword(key);
}
// add more key checks for the other values
// Check if the door is open and if it should be closed
if (isOpen && enteredPassword == "") {
servo.write(closedPos);
isOpen = false;
lcd.setCursor(0, 0);
lcd.print("Closed");
}
delay(100);
}
`

Are you getting the expected analog readings from each keypress? Your ranges look too tight.

...I hate when people use analog when they really want digital. :stuck_out_tongue:

Add a line in the program to output the actual analog values that you are reading from the switch circuit.

Also please auto-format your code using ctrl-T in the IDE, before reposting it inside code tags for the forum.

I tried to piece together the code from various instructions.

Please provide a link to some of those.

Links to where you stole borrowed the code would not hurt.

Posting your code using the IDE Auto Format tool followed by the Copy for Forum tool would not hurt.

Posting a schematic is essential, and also would not hurt.

At a glance I am with @DVDdoug who points out the ridiculously narrow range for a given key.

@anon57585045 IDK WTF is going on here, but time seems to be going in every direction. My testimony would be your response did not appear to me until I had. Responded.

a7

It's not new, sometimes I've noticed posting delays in the forum software.

Hello . I am preparing a project including the use of RFID. I would have few pins in the classic 4x4 keypad wiring. Let me try to solve this problem. But probably a big bite for a beginner.

Hello. Sorry for the bad display. As I wrote, I am a beginner. Which, of course, is no excuse in some ways.

I drew mainly from these sources:

And other instructions that I can't even find right now...

Rather than having one 'if' per key, it would be easier to read if you had a list of keys and a list of analog values:

const char keys[] = "0123456789A#* ";
const int vals[] = {0, 66, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

void loop()
{
  int val = analogRead(A0);
  for (int i=0; i<strlen(keys); i++)
  {
    if (val >= vals[i] - 2 && val <= vals[i] + 2) 
    {
      checkPassword(keys[i]);
      break;  // No need to continue the search for a matching value
    }
  }
}

Hello .
I got a completely different code. It works in a virtual environment. I still have to try the change to LiquidCrystal_I2C.h because I don't know if it will work physically.

// Keypad 4x4 on Analog A0 Pin
#include <Servo.h>
#include <Adafruit_LiquidCrystal.h>
Adafruit_LiquidCrystal lcd_1(0);

int data[] = { 68, 98, 179, 64, 90, 153, 60, 83, 133, 76, 57, 118, 1023, 511, 341, 256 };

String keys = "1234567890*#ABCD";
String pass = "1234D";
String passkey = "";
String access = "";
int key;
int key_lock = false;

int open = 45;
int close = 135;
Servo servo_3;


void setup() {
  pinMode(3, OUTPUT);
  servo_3.attach(3);
  lcd_1.begin(16, 2);
  getlcd(1, 0, 1, 1, "Keypad 4x4 on", "Analog A0 Pin", 0);
  delay(1300);
  getlcd(1, 0, 1, 1, ">> Password <<", "--------------", 1);
  Serial.begin(9600);
}



void loop() {
  key = getKeypad();
  if (key != -1) {
    if (keys[key] == '*') {
      getlcd(1, 0, 1, 1, ">> Password <<", "--------------", 1);
      passkey = "";
      servo_3.write(close);
    } else if (keys[key] == '#') {
      if (passkey == pass) {
        access = "ALLOWED*";
        servo_3.write(open);
      } else {
        access = " DENIED*";
        servo_3.write(close);
      }
      getlcd(0, 0, 8, 0, "*ACCESS", access, 1);
      delay(300);
      if (passkey == pass) {
        getlcd(1, 0, 6, 1, "** Welcome **", "Boss", 1);
      }
      if (passkey != pass) {
        getlcd(1, 0, 1, 1, ">> Password <<", "--------------", 1);
      }
      passkey = "";
    } else passkey += keys[key];

    if (passkey.length() > 0)
      getlcd(-1, -1, passkey.length(), 1, "", "*", 0);
  }
  delay(10);
}

int getlcd(int s1, int z1, int s2, int z2, String text1, String text2, int c) {

  if (c == 1) lcd_1.clear();
  if (s1 != -1 && z1 != -1) {
    lcd_1.setCursor(s1, z1);
    lcd_1.print(text1);
  }
  if (s2 != -1 && z2 != -1) {
    lcd_1.setCursor(s2, z2);
    lcd_1.print(text2);
  }
}



int getKeypad() {
  int ret = -1;
  int keypad = analogRead(A0);
  Serial.println(keypad);
  if (keypad == 0) key_lock = false;
  else if (!key_lock) {

    switch (keypad) {
      ;
      case 68: ret = 0; break;
      case 98: ret = 1; break;
      case 179: ret = 2; break;
      case 64: ret = 3; break;
      case 90: ret = 4; break;
      case 153: ret = 5; break;
      case 60: ret = 6; break;
      case 83: ret = 7; break;
      case 133: ret = 8; break;
      case 76: ret = 9; break;
      case 57: ret = 10; break;
      case 118: ret = 11; break;
      case 1023: ret = 12; break;
      case 511: ret = 13; break;
      case 341: ret = 14; break;
      case 256: ret = 15; break;
      default: ret = -1; break;
    }
    key_lock = true;
  }
  return ret;
}

This only works on exact matches. It may be unworkable in the real world.

Hello.
I modified the code and used ranges. It physically works.

int getKeypad() {
  int ret = -1;
  int keypad = analogRead(A0);
  if (keypad == 0) key_lock = false;
  else if (!key_lock) {

    switch (keypad) {
      ;
      case 63 ... 68: ret = 0; break;
      case 92 ... 98: ret = 1; break;
      case 172 ... 179: ret = 2; break;
      case 59 ... 62: ret = 3; break;
      case 84 ... 90: ret = 4; break;
      case 146 ... 153: ret = 5; break;
      case 56 ... 58: ret = 6; break;
      case 78 ... 83: ret = 7; break;
      case 126 ... 133: ret = 8; break;
      case 71 ... 76: ret = 9; break;
      case 52 ... 55: ret = 10; break;
      case 111 ... 118: ret = 11; break;
      case 969 ... 1023: ret = 12; break;
      case 495 ... 511: ret = 13; break;
      case 331 ... 341: ret = 14; break;
      case 249 ... 256: ret = 15; break;
      default: ret = -1; break;
    }
    key_lock = true;
  }
  return ret;
}

Now I would need to merge the two codes. namely ro RFID and the other on a modified keyboard. And so that both systems work independently. That is: if the RFID is the same - open the servo,,,, or if the code from the keyboard is the same - open the servo.
Some idea?

// Následující kód načítá potřebné knihovny, inicializuje displej a servo,
// definuje hodnoty pro otevření a zavření dveří a dvě UID karty pro přístup,
// a nastavuje počáteční hodnotu proměnné pro kontrolu stavu dveří.
#include <Wire.h>
#include <SPI.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include <MFRC522.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);
MFRC522 mfrc522(10, 9);  // MFRC522 mfrc522(SS_PIN, RST_PIN)
Servo myservo;
int delayTime = 50;
int closed = 140;  // Pozor! kvuli otoceni serva v realnem prostredi jsou prehozeny funkce Open-Close. TZN - Close = otevreno a naopak....!!!
int opened = 110;
String tagUID1 = "BF 95 81 28";  // Řetězec pro uložení UID první karty
String tagUID2 = "60 11 2C 12";  // Řetězec pro uložení UID druhé karty
bool doorOpen = false;

String keys = "1234567890*#ABCD";
String pass[] = { "1234D", "5678A", "9012C" };
String passkey = "";
String access = "";
int key;
int key_lock = false;

void setup() {
  myservo.attach(6);      //  připojení serva k digitálnímu pinu 6.
  myservo.write(opened);  // servo na pozici otevřeno(fyzicky - zavreno)
  lcd.begin();
  lcd.backlight();
  SPI.begin();
  mfrc522.PCD_Init();  //  inicializace čtečky RFID.
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Nedobytny trezor");
  delay(100);
  lcd.setCursor(0, 1);
  lcd.print(" ----Dudasci---- ");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(">> Password <<");
  lcd.setCursor(0, 1);
  lcd.print("--------------");
  delay(1000);
}
// Nastavení, když jsou dveře otevřeny
void open() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Pristup povolen");
  lcd.setCursor(0, 1);
  lcd.print("Oteviram dvere");
  delay(2000);
  for (int pos = opened; pos <= closed; pos += 1) {
    myservo.write(pos);
    delay(delayTime);
  }  // otevreni dveri
  delay(3000);
  lcd.clear();
  lcd.print("Dvere otevreny");
  lcd.setCursor(0, 1);
  lcd.print("Zavri kodem");
  delay(1000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(">> Password <<");
  lcd.setCursor(0, 1);
  lcd.print("--------------");
  delay(1000);
  doorOpen = true;
}

// Nastavení, když jsou dveře zavřeny
void close() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Pristup povolen");
  lcd.setCursor(0, 1);
  lcd.print("Zaviram dvere");
  delay(3000);
  for (int pos = closed; pos >= opened; pos -= 1) {
    myservo.write(pos);
    delay(delayTime);
  }  // zavirani dveri
  delay(2000);
  lcd.clear();
  lcd.print("Dvere zavreny");
  lcd.setCursor(0, 1);
  lcd.print("Otevri kodem");
  delay(1000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(">> Password <<");
  lcd.setCursor(0, 1);
  lcd.print("--------------");
  delay(1000);
  doorOpen = false;
}

// Nastavení , pokud karta neodpovídá
void denyAccess() {
  // pokud karta neodpovídá.
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Pristup zamitnut");
  lcd.setCursor(0, 1);
  lcd.print("Opakuj kod!");
  delay(3000);
}

void loop() {


  // Look for new cards
  if (!mfrc522.PICC_IsNewCardPresent()) {
    return;
  }

  // Select one of the cards
  if (!mfrc522.PICC_ReadCardSerial()) {
    return;
  }

  // Reading from the card
  String tag = "";
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    tag.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  tag.toUpperCase();

  // Checking the card
  if (tag.substring(1) == tagUID1 || tag.substring(1) == tagUID2)  //change here the UID of the card/cards that you want to give access
  {
    // If UID of tag is matched.
    if (!doorOpen) {  // pokud dvere jsou zavreny
      open();
    } else {
      close();
    }
  } else {
    denyAccess();
  }
}

Second code:

#include <Wire.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

int data[] = { 65, 94, 174, 60, 86, 148, 57, 80, 128, 73, 54, 113, 971, 497, 333, 251 };

String keys = "1234567890*#ABCD";
String pass[] = { "1234D", "5678A", "9012C" };
String passkey = "";
String access = "";
int key;
int key_lock = false;

int open = 140;
int close = 110;
Servo servo_3;

void setup() {
  pinMode(6, OUTPUT);
  servo_3.attach(6);
  servo_3.write(close);
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Keypad 4x4 on");
  lcd.setCursor(0, 1);
  lcd.print("Analog A0 Pin");
  delay(1300);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(">> Password <<");
  lcd.setCursor(0, 1);
  lcd.print("--------------");
  Serial.begin(9600);
}

void loop() {
  key = getKeypad();
  if (key != -1) {
    if (keys[key] == '*') {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(">> Password <<");
      lcd.setCursor(0, 1);
      lcd.print("--------------");
      passkey = "";
      servo_3.write(close);
    } else if (keys[key] == '#') {
      if (passkey == pass[0] || passkey == pass[1] || passkey == pass[2]) {
        access = "ALLOWED*";
        servo_3.write(open);
      } else {
        access = "DENIED*";
        servo_3.write(close);
      }
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("*ACCESS");
      lcd.setCursor(8, 0);
      lcd.print(access);
      delay(300);
      if (passkey == pass[0] || passkey == pass[1] || passkey == pass[2]) {
        lcd.setCursor(0, 1);
        lcd.print("** Welcome **");
        lcd.setCursor(6, 1);
        lcd.print("Boss");
      }
      if (passkey == pass[0] || passkey == pass[1] || passkey == pass[2]) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print(">> Password <<");
        lcd.setCursor(0, 1);
        lcd.print("--------------");
      }
      passkey = "";
    } else
      passkey += keys[key];

    if (passkey.length() > 0) {
      lcd.setCursor(passkey.length() - 1, 1);
      lcd.print("*");
    }
  }
  delay(10);
}

int getKeypad() {
  int ret = -1;
  int keypad = analogRead(A0);
  if (keypad == 0) key_lock = false;
  else if (!key_lock) {

    switch (keypad) {
      ;
      case 63 ... 68: ret = 0; break;
      case 92 ... 98: ret = 1; break;
      case 172 ... 179: ret = 2; break;
      case 59 ... 62: ret = 3; break;
      case 84 ... 90: ret = 4; break;
      case 146 ... 153: ret = 5; break;
      case 56 ... 58: ret = 6; break;
      case 78 ... 83: ret = 7; break;
      case 126 ... 133: ret = 8; break;
      case 71 ... 76: ret = 9; break;
      case 52 ... 55: ret = 10; break;
      case 111 ... 118: ret = 11; break;
      case 969 ... 1023: ret = 12; break;
      case 495 ... 511: ret = 13; break;
      case 331 ... 341: ret = 14; break;
      case 249 ... 256: ret = 15; break;
      default: ret = -1; break;
    }
    key_lock = true;
  }
  return ret;
}

I managed to merge the code for the keyboard and the code for the RFID. The keyboard and RFID work independently of each other. Both RFID and Keypad can be used to control the servo (only connected to analog A0). Except for minor errors, the code also works in a real environment. I just didn't manage to slow dervo down in the keyboard section in the code. So the servo jerks somehow when editing the code with deceleration.

#include <Wire.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <MFRC522.h>
#include <SPI.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

MFRC522 mfrc522(10, 9);          // MFRC522 mfrc522(SS_PIN, RST_PIN)
String tagUID1 = "bf 95 81 28";  // Řetězec pro uložení UID první karty
String tagUID2 = "60 11 2c 12";  // Řetězec pro uložení UID druhé karty
bool doorOpen = false;


String keys = "1234567890*#ABCD";
String pass[] = { "1234D", "782013", "9012C" };
String passkey = "";
String access = "";
int key;
int key_lock = false;

int closed = 140;  // Pozor! kvuli otoceni serva v realnem prostredi jsou prehozeny funkce Open-Close. TZN - Close = otevreno a naopak....!!!
int opened = 110;
int delayTime = 25;
Servo servo_3;

void setup() {
  pinMode(6, OUTPUT);
  servo_3.attach(6);
  servo_3.write(opened);
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Nedobytny trezor");
  delay(100);
  lcd.setCursor(0, 1);
  lcd.print("-----Dudasci-----");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" >>Pouzij kod<<");
  lcd.setCursor(0, 1);
  lcd.print(" >pro spusteni<");
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  delay(1000);
}


void open() {
  for (int pos = opened; pos <= closed; pos += 1) {
    servo_3.write(pos);
    delay(delayTime);
  }  // otevreni dveri
  doorOpen = true;
}

// Nastavení, když jsou dveře zavřeny
void close() {
  for (int pos = closed; pos >= opened; pos -= 1) {
    servo_3.write(pos);
    delay(delayTime);
  }  // zavirani dveri
  doorOpen = false;
}

// Nastavení , pokud karta neodpovídá
void denyAccess() {
  // pokud karta neodpovídá.
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Pristup zamitnut");
  lcd.setCursor(0, 1);
  lcd.print("Opakuj kod!");
  delay(3000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" >>Pouzij kod<<");
  lcd.setCursor(0, 1);
  lcd.print(" >pro spusteni<");
}


void loop() {
  // check for RFID tag
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
    String tagUID = "";
    for (byte i = 0; i < mfrc522.uid.size; i++) {
      tagUID += String(mfrc522.uid.uidByte[i], HEX);
      if (i < mfrc522.uid.size - 1) {
        tagUID += " ";
      }
    }
    Serial.println("Detected tag with UID: " + tagUID);
    // check if tag matches authorized tag UID
    if (tagUID == tagUID1 || tagUID == tagUID2) {
      // open door and wait for it to close again
      if (!doorOpen) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Pristup povolen");
        lcd.setCursor(0, 1);
        lcd.print("Oteviram dvere");
        delay(2000);
        open();
        lcd.clear();
        lcd.print("Dvere otevreny");
        lcd.setCursor(0, 1);
        lcd.print("Zavri kodem");
        delay(2000);
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print(">>Zavri kodem");
        lcd.setCursor(0, 1);
        lcd.print("--------------");
        delay(1000);
      } else {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Pristup povolen");
        lcd.setCursor(0, 1);
        lcd.print("Zaviram dvere");
        delay(3000);
        close();
        delay(2000);
        lcd.clear();
        lcd.print("Dvere zavreny");
        lcd.setCursor(0, 1);
        lcd.print("Otevri kodem");
        delay(2000);
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print(">>Otevri kodem");
        lcd.setCursor(0, 1);
        lcd.print("--------------");
        delay(1000);
      }
    } else {
      denyAccess();
    }
  }


  key = getKeypad();
  if (key != -1) {
    if (keys[key] == '*') {
      delay(1000);
      lcd.clear();
      lcd.print("Zaviram dvere");
      delay(2000);
      servo_3.write(opened);
      lcd.clear();
      lcd.print("Dvere zavreny");
      lcd.setCursor(0, 1);
      lcd.print("Otevri kodem");
      delay(2000);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(">>Otevri kodem");
      lcd.setCursor(0, 1);
      lcd.print("--------------");
      delay(1000);
      passkey = "";
      Serial.println("*");
    } else if (keys[key] == '#') {
      if (passkey == pass[0] || passkey == pass[1] || passkey == pass[2]) {
        access = "POVOLEN";
        servo_3.write(closed);
        Serial.println("POVOLEN");
      } else {
        access = "ZAMITNUT";
        servo_3.write(opened);
        Serial.println("ZAMITNUT");
      }
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("PRISTUP");
      lcd.setCursor(8, 0);
      lcd.print(access);
      delay(2000);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(" >>Pouzij kod<<");
      lcd.setCursor(0, 1);
      lcd.print(" >pro spusteni<");
      if (passkey == pass[0] || passkey == pass[1] || passkey == pass[2]) {
        lcd.clear();
        lcd.print("Dvere otevreny");
        lcd.setCursor(0, 1);
        lcd.print("Zavri kodem");
        delay(2000);
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print(">>Zavri kodem");
        lcd.setCursor(0, 1);
        lcd.print("--------------");
        delay(1000);
      }
      passkey = "";
    } else
      passkey += keys[key];

    if (passkey.length() > 0) {
      lcd.setCursor(passkey.length() - 1, 1);
      lcd.print("*");
      Serial.print(passkey.charAt(passkey.length() - 1));
    }
  }
  delay(10);
}

int getKeypad() {
  int ret = -1;
  int keypad = analogRead(A0);
  if (keypad == 0) key_lock = false;
  else if (!key_lock) {

    switch (keypad) {
      ;
      case 63 ... 68: ret = 0; break;
      case 92 ... 98: ret = 1; break;
      case 172 ... 179: ret = 2; break;
      case 59 ... 62: ret = 3; break;
      case 84 ... 90: ret = 4; break;
      case 146 ... 153: ret = 5; break;
      case 56 ... 58: ret = 6; break;
      case 78 ... 83: ret = 7; break;
      case 126 ... 133: ret = 8; break;
      case 71 ... 76: ret = 9; break;
      case 52 ... 55: ret = 10; break;
      case 111 ... 118: ret = 11; break;
      case 969 ... 1023: ret = 12; break;
      case 495 ... 511: ret = 13; break;
      case 331 ... 341: ret = 14; break;
      case 249 ... 256: ret = 15; break;
      default: ret = -1; break;
    }
    key_lock = true;
  }
  return ret;
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.