if statment

when state on inputPin changers one is added to count until count = maxcount then outputPin gose high.
But what i am trying to do is have another count called timeout that only runs when there is no change to the inputPin
but i am just getting the timeout count running all the time

if (carda)      


  {
    digitalWrite (lcdlightPin, HIGH);
    digitalWrite (lightPin, HIGH);
    GLCD.ClearScreen();
    GLCD.CursorTo(2, 0);
    GLCD.Puts("The Queens Head ");
    GLCD.CursorTo(2, 1);
    GLCD.Puts("  2 Pint Card  ");
    GLCD.CursorTo(6, 3);
    GLCD.Puts(" Card A");
    GLCD.CursorTo(2, 7);
    GLCD.PrintNumber(count );
    GLCD.Puts(" Of 2040 Used");



    while(!digitalRead(4))

    {


      if (count > maxcount)     //when count gets to the set number sends 5v to output pin
      { 
        digitalWrite(outputPin, LOW);// power to relay to shut flow 

        GLCD.ClearScreen();
        GLCD.CursorTo(6, 1);
        GLCD.Puts(" NO CREDIT");
        GLCD.CursorTo(5, 3);
        GLCD.Puts("See Bar Staff ");
        GLCD.CursorTo(6, 4);
        GLCD.Puts("For Top Up");
        GLCD.CursorTo(6, 7);
        GLCD.Puts("  Card A");
        delay(4000);
        GLCD.ClearScreen();
        goto bailout; // looks for another card

      } 


      digitalWrite (outputPin, HIGH);
      int newState = digitalRead(inputPin);  //pulse from flow meter

      
      if (newState != lastState)     //detect change

      {
        GLCD.CursorTo(2, 7);
        GLCD.PrintNumber(count );
        GLCD.Puts(" Of 2040 Used");  
        count ++;    //adds one to count

        lastState = newState;


      }  
    
    timeout --;
      GLCD.CursorTo(2, 6);
        GLCD.PrintNumber(timeout );
     


}

@maddave

"if (carda)" is checking what ? Is it carda == 1 ? or carda<>12 ? what ?

But what i am trying to do is have another count called timeout that only runs when there is no change to the inputPin

This doesn't make sense. The inputPin changes whenever what is connected to that pin changes. What is connected to the pin? It's state is either 0 (LOW) or 1 (HIGH).

If you wanted to do something if the pin stayed in the same state for some period of time, that would be a different story.

        goto bailout; // looks for another card

http://arduino.cc/en/Reference/Goto

The use of goto is discouraged in C programming ... The reason that many programmers frown upon the use of goto is that with the unrestrained use of goto statements, it is easy to create a program with undefined program flow, which can never be debugged.

... can never be debugged ...

yes i wanted to do something if the inputPin stayed in the same state for some period of time, but i also want to keep looking for change on inputPin and stop doing it if this change .i can show all the code but it's 1500 lines so i just put the bit i am having prob with .... thanks

Im a bit confused as to what it is you even want to do?.. your end goal/result?

1.) you want to have a variable inputCounter that keeps track of the number of 'times' the pin has changed it state.. (up to a max allowed variable number/changes),........correct?

2.) when you reach maxInputCount threshold/number you want to turn another pin on/high.........correct?

3.) (and I think this is where the question comes into play)... after a 'change' you want to run/start a TIMER that checks to see if the pinState has changed (or counter has increased) in 'xxx' mSeconds... (meaning its 'dead'.. no one is interacting with it...not be used)

is this correct?

If so..

after each 'trigger' (event) start this timer to check every 'xxx' seconds to see if there has been any change.. if after 'xxx' seconds and no 'input'...then do what you want done in your routine.

so start your timer (again) each time an 'input' has been triggered.. you may even want to do it on the start of you program to check and see if anyone is there..

    while(!digitalRead(4))

What is pin 4? inputPin? outputPin?

How about posting the whole sketch? Without seeing if variables are signed, and whether pin 4 is input pin or not, the whole thing is pure guesswork.

And my advice is to restructure so you don't need to use goto.


Your comments are not supported by the code:

  if (count > maxcount)     //when count gets to the set number sends 5v to output pin

{
        digitalWrite(outputPin, LOW);// power to relay to shut flow

That actually sends 0v to the output pin.


This comment doesn't say anything useful:

        count ++;    //adds one to count