watching a digital input while timing

Hey all! First time posting around here. I have had an arduino for years and have always made simple things just to learn and "waste some time". Recently I have been working on a program that will test the pressure of a tube and after a certain sample time will return a pass or fail. I have the code working right now to wait the whole sample time before it returns a pass or fail. What I would like to do is have the program return a fail immediately instead of waiting on the delay() to finish. I just cant seem to figure it out! Thanks for all of the help so far! P.S. How should I attach my code?

Look in the IDE examples (File, Examples, Digital) for the blink without delay sketch. It will show how to use millis() for timing in a non-blocking manner.

This post is also very useful.

I have looked through that for days and am getting nowhere.

Then post your code and maybe we can help.

int at_pressure = 7;
int testing_led = 13;
int pass_led = 8;
int fail_led = 9;
int var = 0;

void setup()
{
Serial.begin(9600);
pinMode(at_pressure, INPUT);
pinMode(testing_led, OUTPUT);
pinMode(fail_led, OUTPUT);
pinMode(pass_led, OUTPUT);
}

void loop()
{
if(digitalRead(at_pressure)==HIGH)
{
Serial.println(“test_started”);
var = 0;
while(var < 8)
{
digitalWrite(testing_led,HIGH);
delay(1000);
digitalWrite(testing_led,LOW);
delay(1000);
var++;

instead of blinking i would like to do a solid light and have it wait for 15 seconds to produce a pass or if it fails i would like it to show it immediately.

}

if(digitalRead(at_pressure)== HIGH)
{
Serial.println(“PASS”);
digitalWrite(pass_led,HIGH);
digitalWrite(testing_led,LOW);
delay(2000);
}
else
{
Serial.println(“FAIL”);
digitalWrite(fail_led,HIGH);
digitalWrite(testing_led,LOW);
delay(2000);
}

}
else
{
digitalWrite(testing_led,LOW);
digitalWrite(fail_led,LOW);
digitalWrite(pass_led,LOW);
}
}

So the sequence is?

turn off all LEDs if pressure high start test, turn on testing LED for 15 seconds, monitor pressure if pressure goes low before 15 seconds, light fail LED, turn off testing LED. if after 15 seconds pressure still high, light pass LED, turn off testing LED.

exactly!

I know i need to use millis() but i am unsure how to make it work in my code.

wahooper1: ... P.S. How should I attach my code?

Use code tags:

[code] ... your code ... [/code]

wahooper1: I have looked through that for days and am getting nowhere.

If you explain what part of Several Things at a Time you don't understand I will try to help.

...R