我需要一些关于按钮计数器的代码帮助。 我想在Arduino做一个柜台。如果我按下按钮,Arduino将增加计数值+1。 我想如果我按住一个按钮,计数器只需在计数值上加1值。 我为它做这个程序.. 请帮我修好程序:(
int pulse = 7;
unsigned long t;
unsigned long previousMillis = 0;
int execussionTime = 1;
long count = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin (9600);
}
void loop() {
// put your main code here, to run repeatedly:
t = millis();
if (digitalRead(pulse) == HIGH){
if(t - previousMillis < execussionTime) // 0 < 1 --> true and doing count + 1
{
count++;
}
}
if(digitalRead(pulse) == LOW){
previousMillis = t;
}
Serial.println(count);
Serial.println(t);
Serial.print("PM = ");
Serial.println(previousMillis);
}