Hello,
I have connected 6 variable resistors across 6 analog pins and calculating the multiplication and average reading through it and storing the value in EEPROM and trying to read it again but when i try to read the eeprom location i get the value which i stored as a test code given in the eeprom.put example how could i store and read the value from a desired location in eeprom
here's my code
#include<EEPROM.h>
int current1 = A0;
int current2 = A1;
int current3 = A2;
int voltage1 = A3;
int voltage2 = A4;
int voltage3 = A5;
float currentValue1 = 0;
float currentValue2 = 0;
float currentValue3 = 0;
float currentFinal1 = 0;
float currentFinal2 = 0;
float currentFinal3 = 0;
float voltageValue1 = 0;
float voltageValue2 = 0;
float voltageValue3 = 0;
float power1 = 0;
float power2 = 0;
float power3 = 0;
float mappedPower1;
float mappedPower2;
float mappedPower3;
float totalPower ;
float averagePower = 0;
int ledPin = 13;
float f = 0.00f;
int eeAddress = 0;
void setup() {
Serial.begin(9600);
pinMode(current1,INPUT);
pinMode(current2,INPUT);
pinMode(current3,INPUT);
pinMode(voltage1,INPUT);
pinMode(voltage2,INPUT);
pinMode(voltage3,INPUT);
pinMode(ledPin,OUTPUT);
EEPROM.get (eeAddress , f);
eeAddress = sizeof(float);
Serial.print("Average power was:");
Serial.println(f);
}
void loop() {
currentValue1 = analogRead(current1);
currentFinal1 = currentValue1/100;
Serial.print("currentValue1:");
Serial.println(currentFinal1);
delay(1000);
currentValue2 = analogRead(current2);
currentFinal2 = currentValue2/100;
Serial.print("currentValue2:");
Serial.println(currentFinal2);
delay(1000);
currentValue3 = analogRead(current3);
currentFinal3 = currentValue3/100;
Serial.print("currentValue3:");
Serial.println(currentFinal3);
delay(1000);
voltageValue1 = analogRead(voltage1);
Serial.print("voltageValue1:");
Serial.println(voltageValue1);
delay(1000);
voltageValue2 = analogRead(voltage2);
Serial.print("voltageValue2:");
Serial.println(voltageValue2);
delay(1000);
voltageValue3 = analogRead(voltage3);
Serial.print("voltageValue3:");
Serial.println(voltageValue3);
delay(1000);
power1 = currentValue1 * voltageValue1;
mappedPower1 = map(power1,0,1023,0,10);
Serial.print("mappedPower1:");
Serial.println(mappedPower1);
delay(1000);
power2 = currentValue2 * voltageValue2;
mappedPower2 = map(power1,0,1023,0,10);
Serial.print("mappedPower2:");
Serial.println(mappedPower2);
delay(1000);
power3 = currentValue3 * voltageValue3;
mappedPower3 = map(power3,0,1023,0,10);
Serial.print("mappedPower3:");
Serial.println(mappedPower3);
delay(1000);
totalPower = mappedPower1+mappedPower2+mappedPower3;
averagePower = totalPower / 3;
Serial.print("Average power:");
Serial.println(averagePower);
f = averagePower;
EEPROM.put(eeAddress, f);
Serial.println(f);
}