“Boolean”的版本间的差异
来自YFRobotwiki
第5行: | 第5行: | ||
<font color="orange" size="+1">'''示例'''</font> | <font color="orange" size="+1">'''示例'''</font> | ||
− | <pre> | + | <pre style="color:dimgray"> |
+ | |||
int LEDpin = 5; // LED on pin 5 | int LEDpin = 5; // LED on pin 5 | ||
int switchPin = 13; // momentary switch on 13, other side connected to ground | int switchPin = 13; // momentary switch on 13, other side connected to ground |
2016年12月26日 (一) 21:01的版本
布尔
一个布尔变量拥有两个值,true或false。(每个布尔变量占用一个字节的内存)
示例
int LEDpin = 5; // LED on pin 5 int switchPin = 13; // momentary switch on 13, other side connected to ground boolean running = false; void setup() { pinMode(LEDpin, OUTPUT); pinMode(switchPin, INPUT); digitalWrite(switchPin, HIGH); // turn on pullup resistor } void loop() { if (digitalRead(switchPin) == LOW) { // switch is pressed - pullup keeps pin high normally delay(100); // delay to debounce switch running = !running; // toggle running variable digitalWrite(LEDpin, running); // indicate via LED } }
扩展阅读
- - 常量
更多建议和问题欢迎反馈至 YFRobot论坛