[問題] arduion變數監看問題
各位版上的大大晚上好。
我正在練習一個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
→
05/07 23:12,
7年前
, 1F
05/07 23:12, 1F
→
05/07 23:13,
7年前
, 2F
05/07 23:13, 2F
推
05/07 23:33,
7年前
, 3F
05/07 23:33, 3F
→
05/07 23:33,
7年前
, 4F
05/07 23:33, 4F
→
05/07 23:33,
7年前
, 5F
05/07 23:33, 5F
→
05/08 10:08,
7年前
, 6F
05/08 10:08, 6F
→
05/08 10:08,
7年前
, 7F
05/08 10:08, 7F
→
05/08 14:03,
7年前
, 8F
05/08 14:03, 8F
→
05/08 14:04,
7年前
, 9F
05/08 14:04, 9F
推
05/08 14:22,
7年前
, 10F
05/08 14:22, 10F
→
05/08 14:22,
7年前
, 11F
05/08 14:22, 11F
推
05/08 14:26,
7年前
, 12F
05/08 14:26, 12F
→
05/08 14:26,
7年前
, 13F
05/08 14:26, 13F
推
05/08 14:31,
7年前
, 14F
05/08 14:31, 14F
→
05/08 14:31,
7年前
, 15F
05/08 14:31, 15F
→
05/08 20:54,
7年前
, 16F
05/08 20:54, 16F
ASM 近期熱門文章
PTT數位生活區 即時熱門文章