Arduino project...

Project.

  1. When a button, say b1, is pressed just for 2 seconds, the output led should be turned on and only when another button, say b2, is pressed or kept hold, the led should be off.

  2. When b1 is pressed and hold for about 4 seconds, the led be on, and turned off only when b2 is either pressed or kept hold again.

In this case, the led should remain on and not be interfered by any signal inputs from b1.

Awaiting early solutions....
Thanks in advance.

Sound like a very reasonable project, eminently achievable. :sunglasses:

Suggest you read the instructions for how to post code (point 7 in that description) and show us your attempts so far so we can discuss them. :grinning:

Noted you never replied to discussion of your previous posts. :roll_eyes:

I must have read that a dozen times, and not sure what it means.

Seems the led comes on if b1 is pressed for either 2s or "about*" 4s, and b2 turns it off?

So if b1 is pressed and released at 1.8s, no led (that's not a "2")
If b1 pressed and released at between say 1.9 and 2.1s, led on (that's a "2")
If b1 pressed and released at say 3s, no led, since that's neither a "2" nor a "4".
If b1 pressed and released at between say 3.9 and 4.1s, led on (that's a "4")
If b1 pressed and released at say 4.2, no led (that's not a "4")

When the led's on, a new b1 has no effect, and a b2 turns it off?

Is that what you're saying?

  • for some definition of "about".

It is possible to detect the moment the button is pressed or released and with millis() it is possible to measure time.
Therefor you can write a better description.

For example:

  1. When button b1 is pressed, the timer starts at the moment it is pressed.
    After two seconds being pressed, the led turns on. When the button is released after that, the led stays on.
    When button b2 is pressed, the led turns off at the moment button b2 is pressed. Button b2 can be released directly after that or being hold, that does not matter.

You can makes such a description for "2.", because what you describe now can be read in different ways.

tonsing:
Project.

  1. When a button, say b1, is pressed just for 2 seconds, the output led should be turned on and only when another button, say b2, is pressed or kept hold, the led should be off.

  2. When b1 is pressed and hold for about 4 seconds, the led be on, and turned off only when b2 is either pressed or kept hold again.

In this case, the led should remain on and not be interfered by any signal inputs from b1.

Awaiting early solutions....
Thanks in advance.

Look at 1. and 2.
Think about them, they are the same functon, just longer presses, but you are using the same buttons.
b1 to turn the LED ON.
b2 to turn the LED OFF.
What is the application that your need this process?
Thanks.. Tom... :slight_smile:

Awaiting early solutions....

That's not how things work here. We will help you arrive at a solution. We won't write all your code for you or provide a complete circuit schematic for you. So don't sit there awaiting!

Koepel:
After two seconds being pressed, the led turns on. When the button is released after that, the led stays on.

That's not the way I read it, but the instructions are a bit ambiguous. I read it that b1 needs releasing at about 2s or at about 4.... but who knows?

Whatever, OP the secret is to capture millis() into a variable when b1 becomes pressed, ala the state change detect tutorial.

PaulRB:
We won't write all your code for you...

... especially since the instructions are unclear so writing code would be postponed pending clarity.

Maybe a timing diagram would be helpful.
When do the buttons open and close?

Perhaps the code magically appear if you wait longer... perhaps if statements can output Boolean based on millis measurements.

The project is synonymous to control a car window.

  1. When a button is pressed, the window rise up until the button is released.

So, same idea with the remaining paragraphs…

tonsing:
The project is synonymous to control a car window.

  1. When a button is pressed, the window rise up until the button is released.

So, same idea with the remaining paragraphs...

So to put it CLEARLY.

RAISE button is a deadman button to raise the window.
The LOWER button is to lower it as a deadman, but if pressed for say 4 seconds after release the window will automatically continue to fully open.
Pressing the opposite button to the travel of the window will stop it.
Tom... :slight_smile:

Hi,
So it is a modification to this?????
https://forum.arduino.cc/index.php?topic=668601.0

Why didn't you say so????

Can you tell us your electronics, programming, arduino, hardware experience?

Tom.... :o

blomcrestlight:
When the led’s on, a new b1 has no effect, and a b2 turns it off?

Is that what you’re saying?

Yes, exactly.

Recall how car window is rolling up.
After the one touch button is pressed, window continue to rise up until another button is pressed. That’s the anology.

Homework ?

tonsing:
Yes, exactly.

Recall how car window is rolling up.
After the one touch button is pressed, window continue to rise up until another button is pressed. That's the anology.

Is this application really for a car electric window?
If so why a button to start UP and another to stop UP?
Electric windows can be dangerous devices?
What is the REAL application?
Thanks.. Tom.. :slight_smile: