hi all. I have a question and looking for suggestions on a problem i'm trying to work out. I have a 10k pot connected to my nano so i can get a value to control an air pump. here's a snippit of the code i'm trying to work out.
void loop(){
int pumpReading = analogRead(pumpPin);
long pumpPeriod = map(pumpReading, 1023, 0, minPump, maxPump);
newPumpPeriod = pumpPeriod;
if (newPumpPeriod != oldPumpPeriod) { monitorPressure(); }
//other code
oldPumpPeriod = pumpPeriod;
} end of loop
Ok. here's my issue. the pumpPeriod can vary + or - 1 every now and then on it's own. It's not a fixed value because it's connected to a pot. and i'm trying to get the monitorPressure() to run whenever the value of the pumpPeriod is adjusted more than 2 points instead of just seeing if it's changed or not. Right now the pumpPeriod resolution is between 200 and 800. And those numbers can't be changed so i can't lower them to make the reading more stable.
So i'm unsure how i can go about using if statements or logical statements or whatever i need to have a 2 point difference between the values before it runs the monitorPressure() function.
Any help is appreciated.