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


Arduino return用法及代碼示例

【控製結構】

說明

如果需要,終止函數並將函數的值返回給調用函數。

用法

return;
return value;

參數

value :允許的數據類型:任何變量或常量類型。

示例代碼

將傳感器輸入與閾值進行比較的函數

int checkSensor() {
  if (analogRead(0) > 400) {
    return 1;
  }
  else {
    return 0;
  }
}

return 關鍵字可以方便地測試一段代碼,而無需"comment out" 可能有錯誤的大段代碼。

void loop() {
  // brilliant code idea to test here

  return;

  // the rest of a dysfunctional sketch here
  // this code will never be executed
}

相關用法


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