Hye . I wrote this program . But it not work as I want .
float energy=0;
val=analogRead(currentSensor);
float power=val*240;
energy=(power/3600)+energy;
if (power>0) {
lcd.setCursor(0,0);
lcd.print(energy);
}
else {
lcd.setCursor (0,1);
lcd.print(energy);
The value energy will increase every minute if power>0 . So I need to display the increase energy value if power>0 .And if power<0 the last energy value will display.
For example , the energy value increase from 0.25 to 0.30. The last value is 0.30 . Then, if the power<0 the energy value will display is 0.30.
Please help me . Thank you .
float power=val*240;
Makes no sense at all because the result of an analogue read is a number between 0 and 1023, it is not a voltage. Turn the reading into a voltage by multiplying it by 5/1024
The value energy will increase every minute
Then the bit of code that says
energy=(power/3600)+energy;
Is a noncense because there is nothing restricting how often you take the samples.
Please post compleat code in code tags if you want to continue to get help here.
float energy=0;
energy = (power/3600) + energy;
This is equivalent to "energy = power/3600;". If you want the value of energy to accumulate, you have to make 'energy' either static or global.
This version will accumulate energy:
static float energy=0;
energy = (power/3600) + energy;