0
我使用按鈕作爲切換開關。按它,它會做「東西A」。再次按下它,它會做「東西B」。爲什麼我無法打電話給我的方法checkButtons_slow()
?爲什麼我按下按鈕後無法調用此方法?
int prev = 0;
int current = 0;
int val4 = 0;
int val5 = 0;
int ledPin = 13;
int prev = 0;
int current = 0;
Servo ZServo;
void setup() {
ZServo.attach(9);
pinMode(pushD3, INPUT_PULLUP);
digitalWrite(3, HIGH);
pinMode(pushD4, INPUT_PULLUP);
digitalWrite(4, HIGH);
pinMode(pushD5, INPUT_PULLUP);
digitalWrite(5, HIGH);
pinMode(pushD6, INPUT_PULLUP);
digitalWrite(6, HIGH);
pinMode(ledPin, OUTPUT);
}
void loop() {
if(digitalRead(3) == LOW) {
current = 1 - current;
}
if(current == 1 && prev == 0) {
checkButtons_slow();
//test: ZServo.write(110);
delay(500); //half a second
}
if(current == 0 && prev == 1) {
ZServo.write(80);
delay(500); //half a second
}
prev = current;
}
這裏是我的方法:
void checkButtons_slow() {
val4 = digitalRead(pushD4);
val5 = digitalRead(pushD5);
if (val4 == LOW) {
ZServo.write(88);
} else if (val5 == LOW) {
ZServo.write(99);
} else {
ZServo.write(91); //GUESSED ON 92; SHOULD TECHNICALLY BE 90
}
}
所以註釋掉//test: ZServo.write(110);
作品。我錯過了什麼checkButtons_slow();
?
@JLH發現了一些可行的東西! – mkpappu
這是一種「去彈跳」的形式,您通常必須在微處理器上進行輪詢輸入引腳以確定按鈕或開關的狀態。 –