Help me out, i have tested all type of combinations of while, else and if during the last 24 hours but can not get it right.
I want to use one button for two functions with a twist.
- press it shortly once and make it high and then let it go, write buzPin HIGH
- press and hold for lets say 300ms code must break; and continue outside buzPin code.
Well, that is done and completed with below code but when i press button and hold inputPin HIGH to exit buzPin code, it will write buzPin HIGH once more and then wait for inputPin to go low before exiting.
My Twist, when i press button and time is greater then 300ms it will exit but not put buzPin HIGH that last time before waiting for inputPin to go low again.
This is my code.
while(//anything just to keep loop) {
digitalWrite(buzPin, LOW);
if (digitalRead(inputPin) == HIGH) {
if (pulseIn(inputPin, HIGH) > 300000) {break;}
digitalWrite(buzPin, HIGH);
delay(100);
}
}
This code will do the same thing but some times it will complete it with the Twist functionallity i am looking for.
while(pulseIn(inputPin, HIGH) < 300000) {
digitalWrite(buzPin, LOW);
if (digitalRead(inputPin) == HIGH) {
digitalWrite(buzPin, HIGH);
delay(100);
}
}
I have tested to play around with the delay time and several debounce codes but no luck. :-[