The Arduino EEPROM library provides the read() and write() functions for accessing the EEPROM memory for storing and recalling values that will persist if the device is restarted or its operation interrupted. Unfortunately, these functions only allow accessing one byte at a time. The float, double (the same as float on most Arduinos), and long data types are all four bytes long, and the int data type is two bytes long, the same length as the word data type. Some trickery is needed to easily store and recall these values.
Continue reading “Saving Floats, Longs, and Ints to EEPROM in Arduino Using Unions”