当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。