its possible to code led turn on and off but if i keep pushing the button for 5 s turn off ?
I don't understand the question.
You mean you don't want the LED to turn off immediately, or if the button is held for less than 5s?
The LED only turns off if you hold the button for at least 5s?
So you need to:
- detect when the button is first pressed
- wait for 5s, or until it's released
- if it's still pressed - turn off the LED.
Yes, for shure.
Yes if i hold the button for 5s led turn off thats what i want
Can u help me ?
So you need to:
- detect when the button is first pressed
- wait for 5s, or until it's released
- if it's still pressed - turn off the LED.
Can u help me with the code please
To restate the problem, which I understood differently,
You want to turn on the LED (if off) when you press the button, or
You want to turn off the LED (if on) when you press the button
And,
You want to turn off the Arduino if the button is pressed for five seconds
Is that what you meant?
That's not what (s)he said in post #4 (in reply to #2)
Gotcha. Missed that. Return to regular station.
bro can you help me with the code ?
What have you tried?
Where are you stuck?
What does google suggest?
@pariston1998 please read How to get the best out of this forum
As you would have been advised to when you joined. It contains valuable advice, including things like how to post your code attempt properly, so we may assess what you're getting stuck on.
This list generally operates on "helping you fix your attempt", rather than "writing it for you", so you'll get more help, more quickly if you actually make an attempt to solve the problem, then present it here.
Thanks
Is this what you want ?
If the LED is currently off and you press the button and release it within 5 seconds then the LED should stay on. If, however, you don't release the button within 5 seconds the LED should turn off again
If the LED is currently on when you press the button it should turn off no matter how long you press the button
Is that what you want ?
You mean, "If the LED is currently on and you press the button and release it within 5 seconds then the LED should stay on" ?
This whole thread seems to be another illustration of where a diagram would convey the information so much more clearly!
is this good ?
void push(int pin) {
// wait until button was pushed down...
while (digitalRead(pin) == LOW);
// ... and released again
while (digitalRead(pin) == HIGH);
}
Where does it check the 5s ?
that's only for detecting the button
That will get "stuck" for as long as the button is held - won't it?
As we don't know exactly what your overall requirement is then it is difficult to say
