Hi!
I'm building an amplifier, and I'm interfacing with an audio chip (PT2314) that has bass and treble adjustment. I want the arduino to store these levels when I unplug the arduino, so I was thinking about storing them in the internal EEPROM. the problem is that the original EEPROM library only support bytes (0 - 255), while the bass and treble level is from -7 to +7. I've red that it IS possible to store larger and negative numbers, but I couldn't figure out how.
This should work (compiles but untested). The range of possibly values is -128 to 127. Hope this helps!
#include <EEPROM.h>
void setup() {
// read a signed 8-bit integer from EEPROM
int8_t value = (int8_t)EEPROM.read(0);
// write a signed 8-bit integer to EEPROM
value = -10;
EEPROM.write(0, value);
}
void loop() {
}
Add 7 before you save. So -7 becomes 0, 0 becomes 7, and +7 becomes 14.
Then when you read the saved number, subtract 7 to get the original number.
This is a simple and perfectly acceptable way to go provided that the range of numbers is constant (-7 to 7) and well defined in all cases.
In fact, I ve seen this technique implemented in commercial applications for example temperature logging where temperature goes negative.