Greetings! I am doing something in this project that when the second button is pressed for 3 seconds it will prompt to a change password where the user must input the old password then the new password if the old password is correct. My only problem is that when the old password is inputted, it automatically updates the old password as the new password. Here's the code and layout in tinkercad
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int s = 0;
int s1 = 0;
int p = 0;
int w = 0;
int column = 0;
int row = 1;
int last = 0;
int nt = 0;
const char chars[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' '};
int previousstate = LOW;
unsigned long duration = 3000;
unsigned long longpress;
bool wstate = false;
const int interval = 50;
unsigned long pt;
unsigned long time;
unsigned long current;
String inputpass;
String newpass;
int cond = 0;
String currentpass = "ab";
void setup()
{
pinMode(13, INPUT);
pinMode(10, INPUT);
pinMode(A0, INPUT);
lcd.begin(16, 2);
Serial.begin(9600);
home();
}
void loop()
{
current = millis();
s = digitalRead(13);
p = analogRead(A0);
w = digitalRead(10);
s1 = map(p, 0, 1023, 0, 26);
lcd.setCursor(column,row);
lcd.cursor();
delay(50);
lcd.print(chars[s1]);
if (s != last)
{
if (s == 1)
{
inputpass.concat(chars[s1]);
column++;
if (column == 16)
{
column = 0;
row=1;
}
}
last = s;
}
if(current - pt > interval)
{
if (w == 1 && previousstate == 0 && !wstate)
{
longpress = current;
previousstate = 1;
Serial.println("Button pressed");
}
time = current - longpress;
if (w == 1 && !wstate && time >= duration)
{
wstate = true;
Serial.println("Button long pressed");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter old pass:");
column = 0;
row = 1;
cond = 1;
inputpass = "";
}
if (w == 0 && previousstate == 1)
{
previousstate = 0;
wstate = false;
Serial.println("Button released");
if (time < duration)
{
Serial.println("Button pressed shortly");
if (cond == 1)
{
if (inputpass == currentpass)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter new pass:");
column = 0;
row = 1;
newpass = inputpass;
inputpass = currentpass;
Serial.print(currentpass);
}
else
{
cond = 0;
lcd.clear();
inputpass = "";
column = 0;
row = 1;
home();
}
}
else
{
if (inputpass == currentpass)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Vault lock is");
lcd.setCursor(6,1);
lcd.print("OPEN");
column = 17;
}
else
{
lcd.clear();
for (int l = 0; l <= 4; l++)
{
lcd.setCursor(4,0);
lcd.print("Error!");
delay(500);
lcd.clear();
delay(500);
}
inputpass = "";
column = 0;
row = 1;
home();
}
}
}
}
pt = current;
}
}
void home()
{
lcd.setCursor(0,0);
lcd.print("Enter Password:");
}
