The reason the AH calc is wrong.
You reset the AH counter every time, thus only updating it with the new value and cumulative.
You need a new unsigned long for previous time.
Thus you will have something along the line of this:
subtracting the current time from the last to get the duration since last measurement, then multiple this by the amp reading and add this to the running total. Since the float for your total ampSeconds should be signed you can even get a negative number.
Code:
unsigned long msec = millis();
float time = msec / 1000.0;
float ampSeconds = Amps*time;
int ampHours = ampSeconds/3600;
return ampHours;
You need a new unsigned long for previous time.
Thus you will have something along the line of this:
Code:
unsigned long msec = millis();
float time = (msec[B]-last[/B]) / 1000.0;
float ampSeconds = [B]ampSeconds +[/B] Amps*time;
int ampHours = ampSeconds/3600;
[B]last = msec;[/B]
return ampHours;