【发布时间】:2015-10-07 17:47:30
【问题描述】:
我使用下面的代码来数字读取引脚输入,看看它是高还是低。
问题是 Arduino 给出了错误的值。即使引脚始终处于低电平,它也会给出一些时间 0 或一些时间高。
虽然引脚为高,但它也给出低或 0 作为答案,有没有人可以帮助我解决这个问题?
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
delay(1000);
// read the input pin:
int buttonState = digitalRead(pushButton);
// print out the state of the button:
Serial.println(buttonState);
delay(1000); // delay in between reads for stability
}
【问题讨论】:
标签: arduino arduino-uno arduino-ide