I worked hard on this.

I worked hard on this. Played around with EEPROM until i figured out how to read and write to it. Im sure someone out there has already done something similar but i felt the need to share this with you guys!

Nice. Good example!

Wouldn’t it make sense to read that stored value during setup() and start with the last pattern? Otherwise there is no reason to save the pattern number, isn’t it? :slight_smile:

I haven’t actually run it yet, but seems like this works as it reads the stored value as soon is it goes into the main loop. It would be a tiny bit more efficient to only read it once at start, but reading every time through the loop should work too, yes?

Works smoothly everytime!

Only concern i have is that EEPROM only has a limited amount of times that it can be written. How exactly does that work?

My recommendation would be to find a multi-function button routine and that you would:

  1. Read the starting mode from EEPROM in setup().
  2. Push the button to advance to the next mode.
  3. Double-click or long click the button to save the current mode to EEPROM.

You can read from EPROM as many times as you want. Writing slowly breaks down the silicon dioxide inside the chip, eventually making it unreliable at keeping the saved data when power cycled. The number of writes before it might become unreliable is 100k or more, so saving the state after each button press is fine.

Ok. Because i plan to have my code based on a similar way to what i wrote yesterday. But with lots more patterns and have that code in the items i plan to sell soon. Dont want the customers complaining that their stuff doesnt want to work anymore and asking for refunds lol. Ive tested and tested and tested all this stuff for the past 6 months just to make sure when i sell something its gonna last. This is a fun hobby :slight_smile: