unsigned long dur_t, start_t;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(3, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(3)==LOW){
dur_t = counting(3);
Serial.println(dur_t);
}
}
unsigned long counting(int pin){
start_t = millis();
while(digitalRead(pin) == LOW){
//do nothing
}
return millis() - start_t;
}