Added a small check to avoid writing into the EEPROM if the previous value is equal to the new one.
Simplified the code a little by using the increment and decrement operators correctly.