pizg 發表於 2011-9-12 12:00:50

壓按鈕累計數值

下列程式有bug, 壓一次按鈕數值會加很多, 請問要如何才能加1累計??

//2011-09-12 bt PizG1位數字顯示器,壓一次按鈕數字累計加1
int ButtonPin = 12;
int ButtonNdx = 0;
void setup() {
Serial.begin(9600);
pinMode(ButtonPin, INPUT);
}
void loop() {
int reading = digitalRead(ButtonPin);
if((reading == HIGH) && (lastButtonState == LOW) ) {
    ButtonNdx++;
    if (ButtonNdx > 9) ButtonNdx = 0;
    Serial.println(ButtonNdx);
}
lastButtonState = reading;
}

g921002 發表於 2011-9-12 14:38:56

彈跳的狀況沒排除...

pizg 發表於 2011-9-12 15:09:21

回復 2# g921002

是啊~~彈跳的情況沒排除,
請問要怎麼改進?

marbol 發表於 2011-9-13 17:23:22

回復g921002

是啊~~彈跳的情況沒排除,
請問要怎麼改進?
pizg 發表於 2011-9-12 15:09 http://www.robofun.net/forum/images/common/back.gif


    加一段延時,到達穩態再計數,或者加一個史密特觸發器 74ls245來修整波形後再用邊緣觸發來計數~~

pizg 發表於 2011-9-13 17:52:18

回復 4# marbol


非常感謝您的回覆.
因為我是Arduino菜鳥, 而且所學也與電子無關,
您的回覆對我來說太深奧,
可否請您直接幫我改一下程式?

cc1357 發表於 2022-3-12 22:09:10



谢谢楼主分享
頁: [1]
查看完整版本: 壓按鈕累計數值