I have installed a flow meter to calculate liquid flow in a system. I get the total flow printed to an LCD screen. I am trying to add a button to reset the value to "0" when pressed, to start the flow calculation over.
I need help!!!
lcd.setCursor(0, 3);
lcd.print("Flow:");
lcd.setCursor(11, 3);
lcd.print(Meter.getTotalVolume()); <----------- This is what I want to reset with the button
lcd.print(" ");
lcd.setCursor(16, 3);
lcd.print("/OPM");
Work through and develop an understanding of the first five demos in IDE -> file/examples/digital. One or more of these are applicable to almost any Arduino project.
The function returns the protected variable _totalVolume. Unless you add a method to the class to zero that out, you're going to have to do something a little different.
For example:
const byte pinZeroVolume = 2; //or whatever pin you want
double
zeroFlowVolume;
byte
lastSw;
void setup()
{
//set up a pin to be the zero button input
pinMode( pinZeroVolume, INPUT_PULLUP );
//and read it's current state for state-change checks
lastSw = digitalRead( pinZeroVolume );
.
.
.
//set the zero flow volume to 0.0 to start
zeroFlowVolume = 0.0f;
.
.
.
}
void loop()
{
byte
swNow;
//read total volume reset switch
swNow = digitalRead( pinZeroVolume );
if( swNow != swLast )
{
//if not the same as last read...
swLast = swNow;
if( swNow == LOW )
{
//...and switch is low (pressed), set the
//zeroFlowVolume variable to the current
//flow volume
zeroFlowVolume = Meter.getTotalVolume();
}//if
}//if
.
.
.
lcd.setCursor(0, 3);
lcd.print("Flow:");
lcd.setCursor(11, 3);
//when printing the flow volume, print the
//difference between the reported total and
//the zero value set when the button was pressed
lcd.print( Meter.getTotalVolume() - zeroFlowVolume );
lcd.print(" ");
lcd.setCursor(16, 3);
lcd.print("/OPM");
.
.
.
}//loop