(Solved) : Consider Combination Lock System Keypad Five Push Buttons Labeled L 2 3 4 5 Purposes Assig Q30683580 . . .
Consider a combination lock system with a keypad having fivepush buttons labeled ‘l’,’2′,’3′, ‘4’ , and ‘5.’ For the purposesof this assignment, your computer keyboard will serve as thekeypad. We start with the system in an UNLOCKED state. In thisstate, the user can press ‘1’ to lock the system, that is put it ina LOCKED state. In this state, the red LED on the PSoC board mustlight up-light up solidly, not blink-and a prompt must be displayedon the terminal requesting that the user enter a five-digitcombination code to unlock the system: Please enter code to unlockthe system: To unlock the system, we must read the input from theuser, one button push at a time from the keyboard, and check forvalidity. If the entered code is valid, the LED is switched off(simulating the system being unlocked). For example, if the validsequence is ‘2’,’4′,’l’,’5′,’3′, then one can develop a finitestate machine to check if the user input matches thiscombination.
The following function develops such a state machine; it retumsI 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 followingenhancements as part of your program. The combination entered bythe user must be processed one button-push at a time. fr@) o(!-roints)
1) If in the UNLOCKED state, theuser must be able to lock the system by pushing ‘1’ anytime.
2) Limit the number ofunsuccessful attempts allowed by locking out the user permanentlyafter three consecutive failed attempts. In this state, the systemmust not respond any more to user input. (For extra credit, you mayimplement a SUPERVISOR state in which the system can only beunlocked by a supervisor using a different five-digit code.)
3) Impose a time limit on enteringthe correct combination in that after the user enters the firstsymbol of the combination, he or she has five seconds to enter theentire sequence. If the time expires during this process, the userhas to enter the entire code again from the beginning.
4) Finally, the finite-statemachine developed in the function assumes that the combination tothe lock is hard-coded. Relax this assumption by extending thefunctionality of the program to accept new combinations at run timeas follows. In the UNLOCKED state, the user must be able to pushthe button ‘2’ to reprogram a new five-digit combination for thesystem. 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 fromhereon. Otherwise the system displays an error and remains in theUNLOCKED state while maintaining the old key. During thereprogramming phase, the LED blinks.
Expert Answer
Answer to Consider Combination Lock System Keypad Five Push Buttons Labeled L 2 3 4 5 Purposes Assig Q30683580 . . .
OR