How would I program for a button that lights up the builtin LED that from the release of the button, delays from turning on for 2 seconds, then turns on for 3 seconds, then turns back off?
I know it would be a modification to the Button example, but I can't figure it out using delay(); .
How would I program for a button that lights up the builtin LED that from the release of the button, delays from turning on for 2 seconds, then turns on for 3 seconds, then turns back off?
turning on for 2 seconds means it is on. then you want to turn it on for 3 seconds.
So why not 5 seconds?
Is there something missing in your description?
Write all your sequences in single lines.
THEN you can generate a code.
But you have to describe it very simply.
Otherwise, the controller will not understand it (me neither ).
Your description needs to include EVERY action e.g.
button pushed - switch LED on
button released - what? maybe switch LED off? You didn't say.
wait 2 seconds
switch LED on
wait 3 seconds
switch LED off.
If that's what you mean then I've almost written the program for you.
erinmags:
How would I program for a button that lights up the builtin LED that from the release of the button, delays from turning on for 2 seconds, then turns on for 3 seconds, then turns back off?
I know it would be a modification to the Button example, but I can't figure it out using delay(); .
congratulations you are absolutely right. it can't be done using delay because delay is blocking.
You concluded right to detect the release of the button the program has to check the button's state pressed or released all the time a lot of times per second to recognize when is the button released and then start new actions.
You are in the situation Robot No 5 loves most "need new input"
The programming-technique for doing this is called non-blocking.
Your wish is switch LED on/off with different delays and depending on a button beeing released.
The recommended example show how to blink two LEDs with different frequencies so this is not exactly the same as what you are looking for but it uses the same programming-technique you need to do this.
It will take you ten minutes to read it and half an hour to copy, paste & compile the example-codes.
The alternative is tinkering around for hours scratching your head why is it still not working.
So give it a try. If it helped you I would love to read your feedback what was still hard to understand
I assume you can figure-out the LED sequence without the button?
You can make a "do nothing" (or "empty") [u]while() loop[/u] that loops while the button is not pushed. ...When you push the button, the looping ends and execution continues-on to the LED sequence.