Hello, I am having a hard time to complete the code. Could you please help me to
ID: 3887374 • Letter: H
Question
Hello,
I am having a hard time to complete the code. Could you please help me to complete this code.
(Note: I am using this program in Arduino for Hardware and Software Interface)
I am writing a code for the EEPROM password, I want to enter 4 digit password followed by enter. That password will save and when I press the switch on the board, a new password will be needed.
I wrote some code in the void setup but I am having a problem for a void loop. Could you help me to complete the void loop? Just provide me the code, I will try in my Arduino device.
Some code is here:
#include <EEPROM.h> // must include this library in order to access EEPROM memory
const int switchPin = 2; // push button switch connected to D2, use for force new password entry
const int flagAddress = 0; // first time power up flag
const int notFirstPowerUpValue = 128; // value used to indicate that is New the first time powered up
const int passwordAddress = 1; // first byte of pasword, need 5 bytes, 4 byte password plus end of string
byte value; // a single byte value when reading from EEPROM
const int lengthPassword = 4; // 4 character password
char *savedPassword = "0000"; // the correct password
char *enterPassword = "0000"; // the user entered password
void setup() {
pinMode(switchPin, INPUT_PULLUP); // tie one side of switch to 5V through pull-up resistor
int pointer; // temp pointer used to read and write password to EEPROM, only
if(digitalRead(switchPin) == false) { // switch is pushed, force password reset
EEPROM.write(flagAddress, 0); // write anything other than 128 to signify first power up
}
Serial.begin(9600);
value = EEPROM.read(flagAddress); // read first time power up flag at EEPROM flagAddress 0
if(value != 128) { // if not notFirstPowerUpValue, this is first power up
Serial.println("This is the first time password up");
Serial.println("Please enter a 4 character password followed by enter");
getPassword(enteredPassword); // get password from keyboard, store in buffer
// write the entered password to EEPROM
pointer = passwordAddress;
for(int i = 0; i < lengthPassword; i++) {
EEPROM.write(pointer, enteredPassword[i]);
}
}
}
void loop() {
// put your main code here, to run repeatedly:
}
It is not necessary to use my code. If you could provide other code.
Thank you.
Explanation / Answer
You will be asked to input 5 digits as password at the initial boot/reset of the device. The first 5 digits you input at installation will be saved as your SET PASSWORD. The device will go LOCKED after setting PASSWORD.
Key A – for unlocking the device. Input correct password and press A for Unlocking.
Key B – for locking any time. Just press B and you will see the LOCKED message.
Key C – for changing the password. Input the correct password and Press C. You will see message asking to ENTER NEW PASSWORD. Enter 5 digits as password. The first 5 digits you enter will be SAVED as NEW PASSWORD.
Exceptions – You can not use keys ‘A’, ‘B’ and ‘C’ inside the password combination. These 3 keys are control keys of the device with specific functions. The program checks for these key presses (at the password setting time – you may see the SetPassword() function and look the condition to check for invalid key press) and identifies them as Invalid Keys. You will have to input 5 new digits as password after an Invalid Key press.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.