void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(3, INPUT_PULLUP);
pinMode(2, OUTPUT);
}
unsigned long duration;
int tog = 0;
void loop() {
// put your main code here, to run repeatedly:
duration = pulseIn(3, LOW);
if(duration > 50){
delay(150);
if(tog == 0){
digitalWrite(2, HIGH);
tog = 1;
}else{
digitalWrite(2,LOW);
tog = 0;
}
}
Serial.println(duration);
}