# If statement with time constraint

Hi, I’m writing a program with the intention of it analyzing the same digital input pin at three different intervals and responding
according to the sequence of HIGHs and LOWs. For example, do one thing if : in between the first press and the first press + 5 seconds, the button is pressed a second time and then, in between the first press + 5 sec. and the first press + 10sec, no button is pressed.
Unfortunately, the arduino compiler states that : “startTime cannot be used as a function”.

I didn’t finish the program yet and wish to fix this problem before continuing.

I 'd like to know how to fix this and if anybody has any alternative ideas as to how I can do the same thing.

``````const int sensPin = 12;

long time;
long startTime = 0;

void setup(){
Serial.begin(9600);
pinMode (12, INPUT_PULLUP);
}

void loop(){
Serial.print("Time: ");
time = millis();

if (sensPin == LOW) {
startTime = millis();

if (sensPin == LOW && (millis() < (startTime + 5000))) {
boolean p1 = 1;
}

else {
boolean p1 = 0;

if (sensPin == LOW && (millis() > (startTime() + 5000)) && millis() < (startTime() + 10 000)) {
boolean p2 = 1;
}

//    if ( millis() = constrain(millis(),starttime() + 5000, starttime + 10 000));
``````
``````if (sensPin == LOW && (millis() > (startTime() + 5000)) && millis() < (startTime() + 10 000)) {
``````

Exactly what the compiler told you. Lose the () after startTime. It is a variable, not a function. Simple typo.

`````` if (sensPin == LOW && (millis() < (startTime + 5000))) {
``````

You got it right here, but you’re doing the math wrong. This will fail on rollover. Instead, do the math this way…

``````if (sensPin == LOW && (millis - startTime  >  5000))
``````

As long as you are using unsigned long integers, that will never fail. Speaking of which…

``````long time;
long startTime = 0;
``````

Should be:

``````unsigned long time;
unsigned long startTime = 0;
``````
`````` if (sensPin == LOW && (millis() < (startTime + 5000))) {
boolean p1 = 1;
}
``````

The variable p1 immediately goes out of scope, so I don’t see the point in setting it to any value.

``````       if (sensPin == LOW && (millis() - startTime > 5000) && (millis() - startTime < 10 000)) {    [code]

this new code gives me a message : " expected ")" before numeric constant"
``````

[/code]

And it highlighted that line? That line looks like it has all it parenthesis right. Sure it didn't highlight a different line? Either way it is telling you that you have some parenthesis messed up somewhere.

Post the entire new code and the entire set of error messages.

`````` startTime < 10 000