
-----------------------------------
AVD
13 Feb 2024 17:03


-----------------------------------
Pare un algoritm de forma:

t = 0

t = t + a1/2
t = t + a2/2
t = t + a3/2
.....
=>
t = 0 + a1/2 + a2/2 + a3/2+...
=>
t = 0 +(a1+a2+a3+..)/2

Astfel algoritmul se transforma in:

a = 0
a = a + a1
a = a + a2
a = a + a3
...
=> t = 0 + a/2

Adica, asa ceva ar fi mai frumos? 
time1 si time2 sunt din nou unsigned long.
    time1=millis();
    [...]
    prev_pwr_used = (prev_pwr+PWR/2)*(time1-time2);
    prev_pwr=PWR;
    time2=millis();
    current_pwr_used = PWR*(time2-time1);
    total_pwr_used = prev_pwr_used + current_pwr_used;
    PWR_TOTAL = PWR_TOTAL + total_pwr_used / 3600000 ; // total power in W*h
