看板 ASM 關於我們 聯絡資訊
各位版上的大大晚上好。 我正在練習一個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); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.195.98.141 ※ 文章網址: https://www.ptt.cc/bbs/ASM/M.1525705009.A.5E7.html ※ 編輯: yimean (123.195.98.141), 05/07/2018 23:00:59
god145145: 你先跑DigitalReadSerial這個範例,開監控視窗看 05/07 23:12
god145145: 然後再看Debounce這個範例 05/07 23:13
johnpage: 5%9c%a8-arduino-uno-r3-%e8%aa%bf%e8%a9%a6debug%e8%8d 05/07 23:33
johnpage: %89%e7%a8%bf%e7%a2%bc/ 05/07 23:33
yimean: @god145145請問一下您說的監控視窗是指串連列阜的嗎? 05/08 10:08
yimean: 可是我的動作都是在本地完成,並沒有跟電腦做溝通。 05/08 10:08
darkster: 你想要監看就是連電腦,把變數進去顯示啊 05/08 14:03
darkster: 丟 05/08 14:04
nissptt: 樓主習慣寫在桌上電腦,筆電執行的程式吧!那才會容易監 05/08 14:22
nissptt: 看。 05/08 14:22
nissptt: Arduino是另一台獨立的電腦,執行中的變數另一台電腦是無 05/08 14:26
nissptt: 法監看的,除非你加寫程式碼主動列印或傳輸出來。 05/08 14:26
nissptt: 不然,就要用模擬器了!但我沒聽過有Arduino和相關元件 05/08 14:31
nissptt: 的模擬器耶! 05/08 14:31
yimean: 原來如此,感謝各位大大的解惑。 05/08 20:54