Several solutions are possible:
There was a NIck Gammon who implemented the big number class which can also do very small numbers
-
http://arduino.cc/forum/index.php/topic,85692.0.html -
Performance is traded for precision !
You could do the math right as it contains an error
total_amp_hours = total_amp_hours + current*(float(period/2160000000));
==> total_amp_hours = total_amp_hours + current * (1.0 * period)/2.16e9);
Final option:
Add the amps per second in an intermediate variable and when a second has passed add its value to the amp_hour
loop()
{
total_amp_second += current * (1.0* period/2.16e9));
if (second has passed)
{
total_amp_hour += total_amp_second;
total_amp_second = 0.0;
Serial.println(total_amp_hour);
}
}
2160000000 is the number of milliseconds in an hour.
In my days there were 3.600.000 milliseconds in an hour, but times seem to go fast in the internet era
