Hi, My sketch uses a buttonlong long press to increment a number from 1 to 8 and then will start over again on 1 on subsequent long presses. My problem is, on a fresh programmed chip, there is a number other than that in my programming address which I've chosen address 0. I tried to fix it in setup by adding
if (progAddress == 0) {
EEPROM.write(progAddress, byte(1));
That didn't work, so it must be a number other than 0. What I would like to do is something like this:
if (progAddress !=(1,2,3,4,5,6,7,8)) {
EEPROM.write(progAddress, byte(1));
My logic is to test for a number 1 -8 and if it's not one of those, it will write a number 1 to the address. This way under normal operation it will always see a 1-8 and will not change the number stored in address 0 every time it starts up.
Thanks, Randy
if (progAddress !=(1,2,3,4,5,6,7,8)) {
EEPROM.write(progAddress, byte(1));
C++ doesn't work that way. You can't compare an integer against a list. To do that comparison you would use
if (progAddress < 1 || progAddress > 8)) {
// If progAddress is less than one OR progAddress is greater than 8
EEPROM.write(progAddress, byte(1));
I'm a bit confused as to why you are checking the ADDRESS of the EEPROM cell rather than the CONTENTS. I thought the ADDRESS was 0 and the CONTENTS was a counter from 1 through 8.
FYI: A freshly erased ATtiny should have 0xFF in every EEPROM location.
johnwasser,you are right, lol, sometimes I crack myself up. I should have just copied the code instead of using my failing memory.
progDelay = EEPROM.read(progAddress); // Delay Seconds written to EEprom
if (progDelay == 0) {
EEPROM.write(progAddress, byte(1));
johnwasser:
FYI: A freshly erased ATtiny should have 0xFF in every EEPROM location.
OH,, thats 255,not zero. No wonder it didn't work! I thought it would simply be 0. I couldn't make heads or tails of the data sheet.
Thanks for your help, Randy