I am currently working on a lasergrid game which is part of a escape room for the scouts. The idea is that they need to pass a lasergrid to get to a keypad with display to input a code which would give them a code to open a numbered lock on the door. Since this game is meant to be possible to be played multiple times I wanted to add a master code to change the password. So far so good the only thing I have an issue with is that this code is not stored in the char array when resetting or powercycling. I have been looking on the web to find the answer for this but it either is to difficult for me to understand at the present moment with the skill level I have, or it is not possible.
This is still work in progress but any help will be much appreciated it is mostly the part from Void passwordchange (at the bottom) where I want to store the changed array Master in the flash or EEPROM (I am not really clear on the location this information is stored).
Thanks again for taking the time to read this and helping me out. I will put the code in the next comment.
Does not save memory, probably compiles to the same. But if you make an error it's a heck more readable.
Some thing like
#define PIN 4;
for example gives pretty complicated errors.
Also, use better variable names. Better a longer but describtive one than a short one. So pin of what? Aka, 'NeoPixelPin' would be a better name.
And for EEPROM read of password:
#include <EEPROM.h>
const byte PasswordLength = 7;
const byte PasswordEepromAddress = 0;
char password[PasswordLength] = "";
void setup(){
for(byte i = 0; i < PasswordLength; i++){
password[i] = EEPROM.read(PasswordEepromAddress + i);
}
}
void loop() {
// put your main code here, to run repeatedly:
}
For writing (only needed when changing it) it's kind of the same. Note, this example uses EEPROM address 0 though 6 including. 'PasswordEepromAddress' only holds the start address. But you have to pick a spot in EEPROM. If the password is the only thing you can stick with 0 like the example.
Note two, the null terminator is also written to EEPROM. You don't really need that but hey, it's easy.
Thank you so much for your help this makes it a lot more understandable. This example makes it very clear. Just a little more code (and soldering) and hopefully this project is finished.
The variable names which are short are mostly due to the fact that these are direct copies from examples and are not yet in use and tweaked, but I will take your advice to heart.
Next time, don't copy it but use it as an inspiration with good varaible names. Makes the code a lot more readable and A LOT easier to debug because of that. Especially if you're new copying seems easy but in the long run (aka, more than blinking a led) it's easier to have understandable code
Definitely! I already butchered/changed a lot of the code and added some of my own I am pretty proud at how far I have come already, but realise I am still in my first babysteps. Learning from books and internet is also pretty difficult I am trying to found a electronics club at my work were a lot of people who has the same interest to join and learn from eachother (and get a experienced coder from our R&D to teach). As long as that is not yet there we need to learn it ourselves .