how can i do a while and read digital input in while

float pressLength_milliSeconds = 0;

// Define the minimum length of time, in milli-seconds, that the button must be pressed for a particular option to occur
int optionOne_milliSeconds = 2000;
int optionTwo_milliSeconds = 100;

//The Pin your button is attached to
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 5; // the number of the LED pin
const int redPin = 7;
const int lidPin = 6;

int Virtual = optionTwo_milliSeconds;
void setup(){
pinMode(buttonPin, INPUT_PULLUP);
// Initialize the pushbutton pin as an input pullup
// Keep in mind, when pin 2 has ground voltage applied, we know the button is being pressed
int buttonState = HIGH;
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(lidPin, OUTPUT);

// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
//Start serial communication - for debugging purposes only
Serial.begin(9600);

} // close setup

void loop() {

//Record roughly the tenths of seconds the button in being held down
if (digitalRead(buttonPin) == HIGH )
{

delay(100); //if you want more resolution, lower this number
pressLength_milliSeconds = pressLength_milliSeconds + 100;

//display how long button is has been held
Serial.print("ms = ");
Serial.println(pressLength_milliSeconds);

}//close while

//Different if-else conditions are triggered based on the length of the button press
//Start with the longest time option first

//Option 2 - Execute the second option if the button is held for the correct amount of time
if(pressLength_milliSeconds >= optionTwo_milliSeconds)

{
digitalWrite(ledPin, HIGH);
// turn LED off:
delay(800);
digitalWrite(redPin, HIGH);
delay(700);
digitalWrite(lidPin, HIGH);
delay(600);
digitalWrite(ledPin, LOW);
digitalWrite(redPin, LOW);
digitalWrite(lidPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
digitalWrite(redPin, HIGH);
delay(900);
digitalWrite(redPin, LOW);
digitalWrite(lidPin, HIGH);
delay(800);
digitalWrite(lidPin, LOW);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin, LOW);
digitalRead( Virtual);

}

//option 1 - Execute the first option if the button is held for the correct amount of time
if (pressLength_milliSeconds >= optionOne_milliSeconds){

digitalWrite(lidPin, LOW);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin, LOW);
}//close if options

//every time through the loop, we need to reset the pressLength_Seconds counter

} // close void loop

Please tell us exactly what you are trying to do.

You should look into using the ‘BWD Blink Without Delay’ technique and avoid using delay().
delay() freezes your code for that amount of time.

Read Robin2’s discussion:
http://forum.arduino.cc/index.php?topic=223286.0

}//close while

The comment does not match the code

float pressLength_milliSeconds = 0;

Why are you storing an integral value in a float?

Do you routinely store fractions in ints?

i try to make arduino to read push button in a while...i think is not so easy and i need help.

float pressLength_milliSeconds = 0;

// Define the minimum length of time, in milli-seconds, that the button must be pressed for a particular option to occur
int optionOne_milliSeconds = 100;
int optionTwo_milliSeconds = 1000;

//The Pin your button is attached to
const int buttonPin = 2;

//Pin your LEDs are attached to
const int ledPin = 5; // the number of the LED pin
const int redPin = 7;
const int lidPin = 6;
int buttonState = digitalRead(buttonPin);
void setup(){

// Initialize the pushbutton pin as an input pullup
// Keep in mind, when pin 2 has ground voltage applied, we know the button is being pressed
pinMode(buttonPin, INPUT_PULLUP);
//set the LEDs pins as outputs
pinMode(ledPin, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(lidPin, OUTPUT);
//Start serial communication - for debugging purposes only
Serial.begin(9600);

} // close setup

void loop() {

//Record roughly the tenths of seconds the button in being held down
while (digitalRead(buttonPin) == LOW ){

delay(100); //if you want more resolution, lower this number
pressLength_milliSeconds = pressLength_milliSeconds + 100;

//display how long button is has been held
Serial.print("ms = ");
Serial.println(pressLength_milliSeconds);

}//close while

//Different if-else conditions are triggered based on the length of the button press
//Start with the longest time option first

//Option 2 - Execute the second option if the button is held for the correct amount of time
if (pressLength_milliSeconds >= optionTwo_milliSeconds){

digitalWrite(ledPin, LOW);
digitalWrite(redPin, LOW);
digitalWrite(lidPin, LOW);

}

//option 1 - Execute the first option if the button is held for the correct amount of time
while(pressLength_milliSeconds >= optionOne_milliSeconds)
{ buttonState = digitalRead(buttonPin);
digitalWrite(ledPin, HIGH);
// turn LED off:
delay(800);
buttonState = digitalRead(buttonPin);
digitalWrite(redPin, HIGH);
delay(700);
buttonState = digitalRead(buttonPin);
digitalWrite(lidPin, HIGH);
delay(600);
buttonState = digitalRead(buttonPin);

digitalWrite(ledPin, LOW);
digitalWrite(redPin, LOW);
digitalWrite(lidPin, LOW);
delay(100);
buttonState = digitalRead(buttonPin);

digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
digitalWrite(redPin, HIGH);
delay(900);
buttonState = digitalRead(buttonPin);

digitalWrite(redPin, LOW);
digitalWrite(lidPin, HIGH);
delay(800);
digitalWrite(lidPin, LOW);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin, LOW);
buttonState = digitalRead(buttonPin);
}

i think is not so easy

It's trivial. If you can read the pin outside of a while statement, you can read the pin inside of the while statement.

No one has successfully combine millis() and delay() in the same program. Your expectation that you can immediately break out of a while loop that is littered with delays is unrealistic.

Delete that code and start over, WITHOUT using a single delay(). It is entirely possible, and even easy, to write non-blocking code. You MUST learn to do that.