Question
Consider a combination lock system with a keypad having five push buttons labeled 'l','2','3', '4' , and '5.' For the purposes of this assignment, your
Consider a combination lock system with a keypad having five push buttons labeled 'l','2','3', '4' , and '5.' For the purposes of this assignment, your computer keyboard will serve as the keypad. We start with the system in an UNLOCKED state. In this state, the user can press '1' to lock the system, that is put it in a LOCKED state. In this state, the red LED on the PSoC board must light up-light up solidly, not blink-and a prompt must be displayed on the terminal requesting that the user enter a five-digit combination code to unlock the system: Please enter code to unlock the system: To unlock the system, we must read the input from the user, one button push at a time from the keyboard, and check for validity. If the entered code is valid, the LED is switched off (simulating the system being unlocked). For example, if the valid sequence is '2','4','l','5','3', then one can develop a finite state machine to check if the user input matches this combination.
The following function develops such a state machine; it retums I if a valid combination is entered, 0 otherwise.
int getCombination
{
int currentstate = -1; /*Our Start State. */
char input;
white (1) {
/* Get button pushed by user via UART. */
input = get.Button{);
switch (input) {
case '1' :
if (currentState == 4)
currentState = 1;
else
return 0;
break;
case '2' :
if (currentState == -1)
currentState = 2;
else
return 0;
break;
case '3':
if (currentState == 5)
return 1;
else
return 0;
break;
case '4':
if (currentstate -= 2)
currentState = 4;
else
return 0;
break;
case '5':
if (currentState == 1)
currentState = 5;
else
return 0;
break;
default:
return 0
} }
}
Starting with the above code snippet, develop the following enhancements as part of your program. The combination entered by the user must be processed one button-push at a time. \fr@) o (!-roints)
1) If in the UNLOCKED state, the user must be able to lock the system by pushing '1' anytime.
2) Limit the number of unsuccessful attempts allowed by locking out the user permanently after three consecutive failed attempts. In this state, the system must not respond any more to user input. (For extra credit, you may implement a SUPERVISOR state in which the system can only be unlocked by a supervisor using a different five-digit code.)
3) Impose a time limit on entering the correct combination in that after the user enters the first symbol of the combination, he or she has five seconds to enter the entire sequence. If the time expires during this process, the user has to enter the entire code again from the beginning.
4) Finally, the finite-state machine developed in the function assumes that the combination to the lock is hard-coded. Relax this assumption by extending the functionality of the program to accept new combinations at run time as follows. In the UNLOCKED state, the user must be able to push the button '2' to reprogram a new five-digit combination for the system. The system displays.
Enter New Key:
prompt on the terminal. After a new five-digit code is entered, the screen displays.
Enter Key Again to Confirm:
and the user enters the code again. If the code is confirmed, system goes back to the UNLOCKED state and the new key is used from hereon. Otherwise the system displays an error and remains in the UNLOCKED state while maintaining the old key. During the reprogramming phase, the LED blinks.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started