//NodeMcu的管脚定义
#define D0 16
#define D1 5
#define D2 4
#define D3 0
#define D4 2//板载Led灯
#define D5 14
#define D6 12
#define D7 13
#define D8 15
int timeReleased = 0;
int startPressed = 0;
void setup() {
pinMode(D4, INPUT_PULLUP);
Serial.begin(9600);
}
//此数字用于返回Arduino板开始运行当前程序时的毫秒数。这个数字在大约50天后重叠,即回到零。
void loop() {
// read the pushbutton input pin:
//buttonState = digitalRead(buttonPin);
//按钮按下
//Serial.println(buttonState);
if (digitalRead(buttonPin) == false) {
timeReleased = millis() - startPressed;
if (timeReleased >= 5000) {
Serial.println("Button idle for 5 second or more");
}
}
else {
startPressed = millis();
}
}
检测Arduino中按下按钮的时间 5S之后输出一个字符串
最新推荐文章于 2024-05-10 13:08:03 发布
