Getting last reading before dropping to zero

Hello Gang!

I have a circuit that I am reading pressure through a small orifice. I use a small air pump for generating air through the orifice. Typical readings I get is 120mmhg. What I want to know is if it is possible and how to program a last reading of 120mmhg etc before popoff of pressure from a diaphragm and it goes back to zero?


Sounds plausible. You could keep a variable LastReading and before you take a reading, set it to CurrentReading.

Alternatively, ignore zero readings i.e. don't update your variables.

Depending on how frequently you take the readings and how fast they drop to zero it may be better to save the last few readings so that you can account for the fact that the reading previous to zero was not, in fact, the highest recorded value, if that is what you want to do

Even easier, each time you take a reading save it if it is the highest value since the pressure was last zero

If you are not trying to record the highest pressure then please expand on what you want to do

Yes record the highest reading.


How frequently will you be taking readings ? I hope that you are doing so very frequently and that you have no blocking code in the loop taking the readings

Something like:

static pressure = 0, lastPressure = 0;
if(pressure > lastPressure)
  lastPressure = pressure;
  lastPressure = 0;