OK. You were reading switches and displaying them here:
https://forum.allaboutcircuits.com/...om-device-in-programming.138302/#post-1159948
That would be a good starting point for reference as well as some of your other threads. Lots of good advice in those from many members.
Your plain language description of the next program is:
I would think a good approach might be to accept switch closures, put each switch value into an array and when you have 4, continue on to checking the stored array against the password kind of like this:
PLEASE NOTE! This is just to get you thinking and is a first thought on my part. You should decide if it makes sense to you. Many details are left out. You'll have to resolve those by flow charting each part.
I would consider putting the password entry into its own function that you call when you want and it returns OK or Bad.
https://forum.allaboutcircuits.com/...om-device-in-programming.138302/#post-1159948
That would be a good starting point for reference as well as some of your other threads. Lots of good advice in those from many members.
Your plain language description of the next program is:
The next step is the flowchart. You can use what worked from the other threads to help you with the details but you'll need to express the logic at the flowchart level before coding (as always).switch button 1 = "1"
switch button 2 = "2"
switch button3 = "3"
switch button 4 ="4"
so this four switch button will work as keypad. user have to press buttons
Suppose password is "4312"
if user enter correct password , LCD display will show message " WELCOME" and If password is wrong. it will show " wrong password "
I would think a good approach might be to accept switch closures, put each switch value into an array and when you have 4, continue on to checking the stored array against the password kind of like this:
Code:
char password[]={"4312"}; // password in ASCII, NUL terminated
char entry[5]; // entry, also NUL terminated
BOOLEAN BadPassword; // error flag
main{
Init
while(1) { // always required
clear entry array by filling with '/0'
// get 4 switches
for n=0 to 3 (get 4 switch closures) {
sample all 4 switches, one at a time, until one is closed
put that switch value into array[n]
display switch value (ASCII)
wait until all switches are open again
}
// 4 switches have been read, array has ASCII switch sequence
// check array
BadPassword = FALSE; // assume good password
// check up to 4 characters
for n=0 to 3{
if password[n] != entry[n]
BadPassword = TRUE; // did not match, set flag
break; // optional, terminates 'for' loop on bad password
}
if BadPassword == TRUE
Display "Wrong Password"
else
Display "WELCOME"
} loop back to while(1) to get another password.
} // end of main
I would consider putting the password entry into its own function that you call when you want and it returns OK or Bad.
Last edited: