Hi everyone! My question is same title: How to reslove this problem when typing a password on matrix keypad? When i'am type a password on matrix keypad, is a crating a problem. When ask to enter password on matrix keypad, my password is 8795, but when i'am type a 8795, in screen is shows 888795. It's duplicating a first number. How to reslove this? This is a my code (in C++):
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include "lcd_i2c_quotes/lcd_i2c.h"
#include "hardware/timer.h"
#include "./pico_keypad4x4/pico_keypad4x4.c"
void loop();
void open();
void clearData();
LCDI2C lcd(0x27 , 2, 16, 16, 17, 0);
#define sifra 5
int pos = 0;
char Data[sifra];
char Master[sifra] = "8795"; int data_count = 0, master_count = 0;
bool Pass_is_good;
char customKey;
uint columns[4] = { 18, 19, 20, 21 };
uint rows[4] = { 10, 11, 12, 13 };
char matrix[16] = {
'1', '2' , '3', 'A',
'4', '5' , '6', 'B',
'7', '8' , '9', 'C',
'*', '0' , '#', 'D'
};
bool vrata = true;
#define bravica 15
int main()
{
stdio_init_all();
gpio_init(bravica);
gpio_set_dir(bravica, GPIO_OUT);
gpio_put(bravica, 1);
lcd.init();
lcd.lcd_clear();
lcd.lcd_set_cursor(0,0);
lcd.lcd_string("UKI COMPUTERS");
lcd.lcd_set_cursor(1, 0);
lcd.lcd_string("--Wait--");
sleep_ms(3000);
lcd.lcd_clear();
loop();
return 0;
}
void clearData()
{
while (data_count != 0)
{
Data[data_count--] = 0;
}
return;
}
void Open()
{
lcd.lcd_clear();
pico_keypad_init(columns, rows, matrix);
char customKey;
lcd.lcd_set_cursor(0, 0);
lcd.lcd_string(" Enter Password");
while (data_count <5)
{
customKey = pico_keypad_get_key();
if (customKey){
Data[data_count] = customKey;
lcd.lcd_set_cursor(1, data_count);
lcd.lcd_string(Data);
data_count++;
sleep_ms(1000);
}
}
}
void loop()
{
if (vrata== 0)
{
pico_keypad_init(columns, rows, matrix);
char customKey;
customKey = pico_keypad_get_key();
if (customKey == '#')
{
lcd.lcd_clear();
gpio_put(bravica, 1);
lcd.lcd_string(" Door is close");
sleep_ms(3000);
vrata= 1;
}
while(1){
tight_loop_contents();
}
}
else Open();
if (data_count == sifra - 1)
{
if (!strcmp(Data, Master))
{
gpio_put(bravica, 0);
lcd.lcd_clear();
lcd.lcd_string(" Door is Open");
vrata= 0;
sleep_ms(10000);
gpio_put(bravica, 1);
lcd.lcd_clear();
lcd.lcd_string(" Door is closed");
vrata= 1;
clearData();
Open();
}
else
{
lcd.lcd_clear();
lcd.lcd_set_cursor(0, 0);
lcd.lcd_string("Wrong password!");
sleep_ms(1000);
lcd.lcd_clear();
pico_keypad_init(columns, rows, matrix);
char customKey;
lcd.lcd_set_cursor(0, 0);
lcd.lcd_string(" Enter Password");
while (data_count <5)
{
customKey = pico_keypad_get_key();
if (customKey){
Data[data_count] = customKey;
lcd.lcd_set_cursor(1, data_count);
lcd.lcd_string(Data);
data_count++;
sleep_ms(1000);
}
}
}
clearData();
}
}
FUN FACT!: I'am when ask some question CodeProject, every time i'am saying "My question is same title: ..." :))).
What I have tried:
I'am tryed converting time_ms interval from 3000 to 1000, and moving a state of this sleep_ms function.