I'm having trouble getting my code to exit the while loop for an inflation/vacuum cycling setup on a pneumatic system. I'm trying to inflate to 1.00PSI and then vacuum to 0.2 PSI and then repeat.
The arduino input is connected to a pressure transducer as input to A0 with the output being a solenoid to D4.
I'm getting the correct PSI reading using the serial monitor within the loop but it doesn't exit the while loop when the level is reached.
I've tried a few different ways and if loops but can't seem to get it. Not sure what I'm doing wrong.
int solenoidPin = 4; //This is the output pin on the Arduino
int cycles;
const int analogPin = A0;
float PSI;
bool inflatestatus = false;
void setup() {
// put your setup code here, to run once:
pinMode(solenoidPin, OUTPUT); //Sets the pin as an output
Serial.begin(9600);
while (! Serial); // Wait untilSerial is ready - Leonardo
Serial.println("Inflation/Deflation Cycling Jig");
}
void loop()
// put your main code here, to run repeatedly:
{
float PSI = ( analogRead(A0) - 204.80 ) * 15.00 / ( 1024 - 204.80 );
if(!inflatestatus)
{
while (PSI < 1.00)
{
digitalWrite(solenoidPin, HIGH); //Switch Solenoid OFF
delay(250);
float PSI = ( analogRead(A0) - 204.80 ) * 15.00 / ( 1024 - 204.80 );
Serial.print(PSI);
Serial.print("PSI ");
}
inflatestatus = true;
}
if(inflatestatus)
{
while (PSI > 0.2)
{
digitalWrite(solenoidPin, LOW); //Switch Solenoid ON
delay(250);
float PSI = ( analogRead(A0) - 204.80 ) * 15.00 / ( 1024 - 204.80 );
Serial.print(PSI);
Serial.print("PSI ");
}
inflatestatus = false;
}
cycles ++;
Serial.print(cycles);
Serial.println('\n');
}