I'm trying to create a sketch to store values in the range 0-100 to EEPROM, and while mucking about I think I used LONG variables which updated multiple EEPROM addresses. To get back to something useful, I want to reset the 12 addresses to something non-zero as follows:
#include <EEPROM.h>
#define NUM_PWM_CHNLS 12 // max 12 for TLC5971
void setup() {
Serial.begin(9600);
Serial.println("============================================================");
for (int i = 0; i < NUM_PWM_CHNLS; i++) {
float f = 0.00f; // Variable to store data read from EEPROM
EEPROM.get( i, f );
Serial.print("EEPROM f val read from address ");
Serial.print(i);
Serial.print(": ");
Serial.println( f, 3 ); // This may print 'ovf' or 'nan' if the data inside the EEPROM is not a valid float.
}
// Reset all EEPROM addresses to initial values
for (int i = 0; i < NUM_PWM_CHNLS; i++) {
EEPROM.write( i, 5 );
}
Serial.println("============================================================");
for (int i = 0; i < NUM_PWM_CHNLS; i++) {
float f = 0.00f; // Variable to store data read from EEPROM
EEPROM.get( i, f );
Serial.print("EEPROM f val read from address ");
Serial.print(i);
Serial.print(": ");
Serial.println( f, 3 ); // This may print 'ovf' or 'nan' if the data inside the EEPROM is not a valid float.
}
}
void loop() {
}
But it doesn't work! Here's the serial monitor output:
============================================================
EEPROM f val read from address 0: 0.000
EEPROM f val read from address 1: 0.000
EEPROM f val read from address 2: 0.000
EEPROM f val read from address 3: 0.000
EEPROM f val read from address 4: 0.000
EEPROM f val read from address 5: 0.000
EEPROM f val read from address 6: 0.000
EEPROM f val read from address 7: 0.000
EEPROM f val read from address 8: 0.000
EEPROM f val read from address 9: 0.000
EEPROM f val read from address 10: ovf
EEPROM f val read from address 11: nan
============================================================
EEPROM f val read from address 0: 0.000
EEPROM f val read from address 1: 0.000
EEPROM f val read from address 2: 0.000
EEPROM f val read from address 3: 0.000
EEPROM f val read from address 4: 0.000
EEPROM f val read from address 5: 0.000
EEPROM f val read from address 6: 0.000
EEPROM f val read from address 7: 0.000
EEPROM f val read from address 8: 0.000
EEPROM f val read from address 9: 0.000
EEPROM f val read from address 10: ovf
EEPROM f val read from address 11: nan
What am I doing wrong?

