Hi all, I have a quite complex program that controls a pump.
Basically I have everything reading correctly and measuring correctly. However my IF statement(s) that control the pump do not work at all. The serial output shows non of the flags activating when the logic in the IF statements should of turned them on.
I've attached the scripts if someone could have a look that would be great!!!
I've also included a copy of the serial output on the Arduino.
psi=0.01, smooth=0.00, setpoint=0.20, Delta=0.00, Person=false, pumpOn=false
At this point surely it should activate the first IF statement in the program?
// ---------------------------------
// Control the pump
// ---------------------------------
// This part runs every 200ms.
// If that is too slow, perhaps this should be run outside the millis() software counter,
// or another millis() software counter could be used.
static int pumpCountOn = 2;
//if there is NOT someone on the mattress AND actual pressure is smaller than 0.2PSI
//then activate the pump. If NOT then deactivate the pump
if ((flagPerson == false) && (smoothPSI < setpoint))
pumpOn = true;
else
pumpOn = false;
// if someone IS one the mattress AND actual pressure is smaller than the setpoint
//then activate the pump. OTHERWISe deactivate the pump
if ((flagPerson == true) && (smoothPSI < setpoint))
pumpOn = true;
else
pumpOn = false;
// if the pumpOn flag is true then activate the transistor to allow the pump to come on.
//if not then make sure the transistor is off.
if (pumpOn == true)
digitalWrite(transistorPin, HIGH);
else
digitalWrite(transistorPin, LOW);
//if noone is on the mattress but the pressure is over 0.2PSI then let some air out.
if ((flagPerson == false) && (smoothPSI > 0.2))
prvOpen = true;
else
prvOpen = false;
//if someone is on the mattress and the pressure is over the desired setpoint then let some air out.
if ((flagPerson == true) && (smoothPSI > setpoint))
prvOpen = true;
else
prvOpen = false;
//turn on the PRV if the flag is set true.
if (prvOpen == true)
digitalWrite(prvPin, HIGH);
else
digitalWrite(prvPin, LOW);
}
}