覆盖延迟和循环

时间:2017-10-05 09:18:12

标签: arduino arduino-uno

是否可以覆盖延迟以结束循环? 我想要发生的是按下按钮结束循环。但它似乎在执行next()方法之前完成循环。

void blink1() {
  loop_flag = true;
  while (loop_flag) {
    // Loop for Lights
    for (int x = 0; x < LED_IN; x++) {
      btn_press = digitalRead(btn_1);
      if (!btn_press) {
        digitalWrite(LED_BUILTIN, HIGH);
        next(); //loop_flag = false; is stored
      } else {
        digitalWrite(LED_BUILTIN, LOW);
        digitalWrite(led[x], HIGH);
        delay(1000);
        digitalWrite(led[x], LOW);
      }
    }
  }
}

void next() {

  Serial.write("pressed next \n");
  flag = getFlag(flag); // Sets new Flag
  loop_flag = false; //ends the loop flag
  delay(100); //delay for button friendly

}

1 个答案:

答案 0 :(得分:0)

即使按下按钮,也会完成for循环。一旦完成对next()的调用,它就会返回到for循环中。加分;在你打电话给next()之后