Calling loop() after noLoop() without user input?

edited September 2014 in Arduino

I am trying to achieve a simple delay function, without using timers. This is needed to call functions in a sequence or in a for loop. It seems that calling noLoop() would be perfect for this, except that you cannot call loop() again after a certain amount of time has passed?

Example: (from Arduino)

loop() {  
  functionOne();  
  delay(100);  
  functionTwo();  
  delay(200);  
  for(int i = 0;i<10;i++) {  
     functionThree();  
     delay(50);  
  }  
}  

Answers

  • Why can't you call loop() again after a certain amount of time has passed?

    Why are you trying to avoid using a timer?

    Can you post an MCVE (not your whole project, but not a disconnected snippet that we can't run)?

  • How would I call loop() (after the loop is stopped), without user input after a certain amount of time?

    This is a code example that executes a different function every 5 seconds. I find it rather unwieldy, and it doesn't work inside a for loop.

    int state = 0;
    long lastTime = 0;
    
    void setup() {
      lastTime = millis();
    }
    void draw() {
      if ( millis() - lastTime > 5000 ) {
        switch(state){
          case 0:
            functionOne();
            break;
          case 1:
            functionTwo();
            break;
          case 2:
            functionThree();
            break;
        }
        state++;
        if(state == 3) state = 0;
        lastTime = millis();
      }
    }
    
  • edited September 2014

    http://forum.processing.org/two/discussion/110/trigger-an-event

    // forum.processing.org/two/discussion/7211/
    // calling-loop-after-noloop-without-user-input
    
    static final int TIMER = 5 * 1000;  // 5 seconds
    
    void setup() {
      noLoop();
      thread("timer");
    }
    
    void draw() {
      print("Triggered\t");
    }
    
    void timer() {
      for (;; redraw())  delay(TIMER);
    }
    
  • How would I call loop() (after the loop is stopped), without user input after a certain amount of time?

    Again, why are you trying so hard to avoid using a timer of some kind? That's pretty much the definition of what you're looking for.

Sign In or Register to comment.