I want to collect voltage in 10bit form customary to the analogRead() function and store them in a "non-voliatile" register, hence EEPROM. The clunky conditional checks if the thing is attached to it's home, where it puts, or my computer where that pin6 is pulled up, and it gets. My data type is int long. I increment 8 bytes just to be "safe" and make this thing go easy the first time.
I just get 0's.
I haven't messed with these for two decades. I'm not adept.
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
eeAddress = 0;
pinMode(6, INPUT_PULLUP);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(6) == LOW) {
int long a2 = analogRead(A2);
EEPROM.put(eeAddress, a2);
eeAddress = eeAddress + 8;
int long a3 = analogRead(A3);
EEPROM.put(eeAddress, a3);
eeAddress = eeAddress + 8;
}
if (digitalRead(6) == HIGH) {
EEPROM.get(eeAddress, tot);
Serial.print("A2: ");
Serial.print(long(lngRead));
eeAddress = eeAddress + 8;
EEPROM.get(eeAddress, tot);
Serial.print(" ... A3: ");
Serial.println(long(lngRead));
eeAddress = eeAddress + 8;
}
delay(500);
}
The analogRead() returns an integer. analogRead() - Arduino Reference.
You can store that as a two-byte int. There is no need to overdo something, that only makes it confusing.
Your eeAddress is set to zero at setup(), after that it is incremented. That is not how to use a EEPROM location.
In the next snippets I assume that it is for an Arduino Uno (Nano/Mega/Micro) board and a 'int' is two bytes.
// Example of storing all of them.
for( int i=0; i<6; i++) // channel 0...6
{
int rawADC = analogRead( i); // analogRead( i) or analogRead( i + A0)
int offset = i * 2; // two bytes per value
EEPROM.put( offset, rawADC);
}
// Example to retrieve A2 from EEPROM
int i = 2; // channel 2
int offset = i * 2; // two bytes per value
int rawADC;
EEPROM.get( offset, rawADC);
Serial.println( rawADC);