[问题] 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