Boolean:修訂版本之間的差異
出自YFRobotwiki
(由1名用戶作出的2個中途修訂版本未被顯示) | |||
第 1 行: | 第 1 行: | ||
− | + | {| border="0" cellpadding="20" width="100%" | |
+ | |- | ||
+ | |width="100%" valign="top" align="left"| | ||
+ | |||
+ | |||
+ | ''' 布尔''' | ||
一个布尔变量拥有两个值,[[常量|true]]或[[常量|false]]。(每个布尔变量占用一个字节的内存) | 一个布尔变量拥有两个值,[[常量|true]]或[[常量|false]]。(每个布尔变量占用一个字节的内存) | ||
第 5 行: | 第 10 行: | ||
<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 | ||
第 36 行: | 第 42 行: | ||
:- [[常量]] | :- [[常量]] | ||
− | + | |} | |
2017年9月10日 (日) 17:03的最新修訂版本
一個布爾變量擁有兩個值,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論壇