How to get read user input from DAQ for a given time interval?
It sounds like you are trying to register when a push button has been pressed for 5 seconds. In other words, you want your flag to turn on after the button has been held for at least 5 seconds, and then turn off once the user releases the button.

I would suggest looking at the example programs to do with button debounce. In particular, the debounce example/tutorial from the Arduino website.

My version of the program would look like this:

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2;    // the number of the pushbutton pin
const int ledPin = 13;      // the number of the LED pin

// Variables will change:
int buttonOutput;            // the current reading from the input pin
int lastReading = LOW;       // the previous reading from the input pin

// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 5000;  // the debounce time; 5000ms = 5 seconds

void setup() {
    pinMode(buttonPin, INPUT);
    pinMode(ledPin, OUTPUT);

    // set initial LED state
    digitalWrite(ledPin, LOW);
}

void loop() {
    // read the state of the switch into a local variable:
    int reading = digitalRead(buttonPin);

    // check to see if you just pressed the button
    // (i.e. the input went from LOW to HIGH), and you've waited long enough
    // since the last press to ignore any noise:

    // If the switch changed, from off to on (LOW to HIGH)
    // ie, reading == HIGH and lastReading == LOW
    if (reading &amp;&amp; !lastReading) {
    // reset the debouncing timer
    lastDebounceTime = millis();
    }

    // If the button is still pressed
    if (reading) {
        // and has been pressed for longer than the debounce delay
        if ((millis() - lastDebounceTime) &gt; debounceDelay) {
            // Then turn on the button output
            buttonOutput = HIGH;
        }
    } 
    else {
        // However if the button is not pressed, then turn off the button output
        buttonOutput = HIGH;
    }

    // set the LED:
    digitalWrite(ledPin, buttonOutput);

    // save the reading. Next time through the loop, it'll be the lastReading:
    lastReading = reading;
}


The second part of your question asks how you can register a button press after a complete button press cycle. In other words; the button is pressed, the button is released - only after this cycle has completed recognise it as a button push.

You don't have to detect the whole cycle, all you have to detect is the button being released. After all, the button cannot be released if it hasn't been pressed first.

You could adapt the State Change Detection example/tutorial from the Arduino website so that it is looking for the falling edge of the button input.

You could simplify the edge detection statements to the following:

if (!buttonState  &amp;&amp; buttonStateLast) {


Basically it requires the last reading of the button to be HIGH and the current reading of the button state to be a LOW.