Ok, I posted what is basically this code a while ago asking for help on another topic, I have a numberpad, with a hardcoded password. which when entered correctly it moves a servo and lights the led on 13.when incorrect it shuts the servo, I will also decide on a way to shut the servo after another input later in the project.

For now I really want to add a user changeable password into it. I have practiced writing single keystrokes to EEPROM but I havent been able to save multiple keystrokes.

I need to somehow interrupt the code with a button press so that it goes into programming mode, it then needs to record the following four keystrokes, and save them to eeprom so that it can be used for the following password.

Can someone help ? I have already spent a few hours googling it and found an example but you have to pay 10 dollars to subscribe to the site before they show you the code

switch (keypad.getState()){ case RELEASED: digitalWrite(ledPin,LOW); EEPROM.write(1, prevkey1); }It doesn't make sense to keep calling the same function. The function returned a value. Select which action to perform based on that value. Don't keep asking for a new value.

Writing the value assigned to prvkey1, which happens only when the key is held, to EEPROM, in the first position, doesn't make sense.

Quote

I need to somehow interrupt the code with a button press so that it goes into programming mode

"Interrupt" isn't the correct term. You need, when some input arrives, to change to "reset password" mode. What input are you planning to use? Wiring an additional switch seems like the best solution.

The time/place to save data in EEPROM is when checkPassword() is called WHEN IN PROGRAMMING mode.

switch (keypad.getState()){ case RELEASED: digitalWrite(ledPin,LOW); EEPROM.write(1, prevkey1); }It doesn't make sense to keep calling the same function. The function returned a value. Select which action to perform based on that value. Don't keep asking for a new value.

This was purely for testing the eeprom writing,

The plan will be to use an external switch for this in the future, Right now I will concentrate on the mechanical part of the project as I currently have a password, albeit hardcoded and non changeable, and I have the servo reacting as I want,

The physical part has now taken priority, as with all things, looks are more important

Hi again, So I have succesfully got the project to open and shut a mechanism when the correct "password" is entered, but that password remains hard coded and I would like to be able to change it and store it in the eeprom. I suppose that the way of doing that is to strore the new string in eeprom and then read it out and set the password as that,

has anyone got any experience with doing this using the password library ? any pointers in the right direction ? thanks,

has anyone got any experience with doing this using the password library ?

"this" would be storing a string in EEPROM, and then reading that string from EEPROM and calling setPassword() with the string?

No, but I know plenty about storing characters in EEPROM, and reading from EEPROM. Using the characters in a call to setPassword() seems pretty simple, then.

I see that you have some steps that need to be implemented.1) Determine that you are in password-define mode vs. password-entry mode.2) When the "enter" key is pressed to define the end of the password, you need to check which mode you are in.3) Store the string in EEPROM. Since each character takes one address, a for loop makes this trivial, regardless of the length of the password string.4) Read the password from EEPROM (in setup(), most likely). The only trick here is knowing how long the string is. Make the length the 1st value stored, or store a NULL at the end, and read until you find the NULL.5) Call password.setPassword() with the string read from EEPROM.

Note that setPassword() does NOT copy the password into a field in the Password class. It simply defines a pointer to where the password is stored (somewhere on the heap in the snippet you showed). So, the area where the password is stored must have program lifetime (like a global variable) rather than function lifetime (such as while setup() is running).

Paul , thanks for the pointers, I will practice saving a string to eeprom, that seems to be the hardest part for me,

Right now I'm working on the physical side of the project, as the appearance of a set password (albeit hard coded) is good enough for the proof of concept and there are many other small hurdles to get over with other aspects of it,