The problem is with var1++. It doesn't increase the value of var1. It always stays 0.00. Actually I can't perform any operation with var1 as rValue. I I put something like var1=3.14 the value changes and gets stored.
With no other pins in use, why are you using analog pin 5 for the switch? You can. There is nothing wrong with doing so, as long as you are actually connecting the switch to analog pin 5, and using an external pull-up resistor.
What evidence do you have that the switch is being read correctly?
I have noticed that if you pass a variable by reference to a function and assign 0xFF to its bytes hapens exactly the same. After programing eeprom is 0xFF.
If I zero out the bytes I use for storing everithing looks fine.
void setup() {
int i;
//using the first byte as an indicator for the first run after programming.
if (EEPROM.read(0) == 0xff) {
EEPROM.write(0,0x00);
for (i=0; i<20; i++) { //i could be up to 512
EEPROM.write(i,0x00);
}
}
read_c();
Serial.begin(9600);
pinMode(sw_0, INPUT);
}
}