當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Arduino Scheduler - yield()用法及代碼示例

調用時將控製權傳遞給其他任務。理想情況下,yield() 應該用於需要一段時間才能完成的函數。

用法

yield();

參數

None。

返回

None。

示例

#include <Scheduler.h>

int counter = 0;
int counter1 = 0;

void setup() {
  Serial.begin(9600);
  Scheduler.startLoop(loop1);
}

void loop () {
 analogWrite(9, counter);
 counter++;

 if (counter > 255){
  counter = 0;
 }

 delay(33);
}

void loop1 () {
 if (Serial.available()) {
    char c = Serial.read();

    if (c=='0') {
      digitalWrite(2, LOW);
      Serial.println("Led turned OFF!");
    }

    if (c=='1') {
      digitalWrite(2, HIGH);
      Serial.println("Led turned ON!");
    }
  }

 yield();
}

相關用法


注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 Scheduler - yield()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。