Boolean
從 YFRobotwiki
布爾
一個布爾變量擁有兩個值,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論壇