Function Timeout Not working


hello all! following snippet of code, supposed self-exit after amount of time using loop. (time out)
however, when function runs, timeout seems skip (or short) , goes straight "program complete"

i haven't used for-loops yet. awesome! :)

code: [select]
void program1() { //just 1 piece of code
  serial.println(">running program 1");
  serial.println("all data lines closed during operation");
  serial.println("this program has timeout, not exit");
  int timeout;
  attachfeet(); //this attaches 2 servos
  delay(500);
  (timeout; timeout > 200000; timeout++) { //the program supposed exit after amount of time
    statechange(); // function determins if there obstacle w/ hc-sr04 sensor
    if (forwardobstacle == false) {
      walkforward();
    }
    else {
      stop();
      delay(50);
      walkleft();
      delay(500);
      stop();
      delay(50);
    }
    delay(10);
  }
  serial.println(">program complete");
}

you more typically see this:

code: [select]

uint32_t ts = millis();
while(millis() - ts > timeout_period)
{
  dosomething();
}


Arduino Forum > Using Arduino > Programming Questions > Function Timeout Not working


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts