[問題] arduion變數監看問題

作者: yimean (溫柔殺手)   2018-05-07 22:56:46
各位版上的大大晚上好。
我正在練習一個LED自保持,直到Button 再次Taggle時才改變LED狀態的程式
目前遇到的問題如下,如果按鈕按的時間比較長,動作就會異常。
目前推估應該是Loop持續執行,導致變數一直被更新,所以動作異常。
所以想問一下有沒有哪一個IDE可以查看變數變化?
我的環境及程式如下。
HW:Arduino UNO version 3
IDE: Arduino 1.8.5 for windwos
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int LEDstatus = 0; //if LEDstaus = 0, LED off, LEDstatu = 1, LED on
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
LEDstatus = 1 - LEDstatus;
}
if (LEDstatus == 1){
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
作者: god145145   2018-05-07 23:12:00
你先跑DigitalReadSerial這個範例,開監控視窗看然後再看Debounce這個範例
作者: johnpage (johnpage)   2018-05-07 23:33:00
http://chenjohn.myqnapcloud.com/%e5%a6%82%e4%bd%95%e5%9c%a8-arduino-uno-r3-%e8%aa%bf%e8%a9%a6debug%e8%8d%89%e7%a8%bf%e7%a2%bc/
作者: yimean (溫柔殺手)   2018-05-08 10:08:00
@god145145請問一下您說的監控視窗是指串連列阜的嗎?可是我的動作都是在本地完成,並沒有跟電腦做溝通。
作者: darkster (草民)   2018-05-08 14:03:00
你想要監看就是連電腦,把變數進去顯示啊丟
作者: nissptt (niss)   2018-05-08 14:22:00
樓主習慣寫在桌上電腦,筆電執行的程式吧!那才會容易監看。Arduino是另一台獨立的電腦,執行中的變數另一台電腦是無法監看的,除非你加寫程式碼主動列印或傳輸出來。不然,就要用模擬器了!但我沒聽過有Arduino和相關元件的模擬器耶!
作者: yimean (溫柔殺手)   2018-05-08 20:54:00
原來如此,感謝各位大大的解惑。

Links booklink

Contact Us: admin [ a t ] ucptt.com