سلام
چطور میتونم مدت زمان یک کلید پل 4 پایه رو تشخیص بدم ؟
چطور میتونم مدت زمان یک کلید پل 4 پایه رو تشخیص بدم ؟
[FONT=Yekan]int inPin = 7;[/FONT]long secs_held; unsigned long firstTime; boolean buttonPressed; boolean onec =true; void setup() { Serial.begin(9600); digitalWrite(inPin, HIGH); } void loop() { if(digitalRead(inPin) == HIGH) { if(onec == true) { buttonPressed = true; firstTime = millis(); Serial.print("First Time: "); Serial.println(firstTime); onec = false; } } if(digitalRead(inPin) == LOW && buttonPressed == true ) { millis_held = (millis() - firstTime); secs_held = millis_held / 1000; Serial.print("Hold Time: "); Serial.println(secs_held); buttonPressed = false; onec = true; } [FONT=Yekan]}[/FONT]
دیدگاه