Go Down

Topic: Button States and LED functions. (Read 677 times) previous topic - next topic

xd41efisc

I have been playing around with this for the last few weekends, and have not come up with a
satisfactory result.

What I am trying to do is:

If a button is pressed momentarily, an LED will flash for X seconds, then STOP.

If the same button is held down, the LED will flash for X seconds, then STOP for X seconds, then flash
for X seconds, then STOP, and do this continuously for X amount of time, OR until the button is released.

The LED also has to go HIGH the moment the button goes HIGH.
This also needs to use no delay.

I have been able to get the two different objectives to work separately but not together, and the other problem is the LED starts LOW.

I have tried that many sketches here I have lost track of what each one was doing.
I have also been through that many threads on here and stack exchange, and have not found anything
that meets these requirements.

If someone can help with some code or point me too some other thread that may be of help, it would be much appreciated.

Thanks.

PieterP

Do you just want a sketch that works, or do you want to pick up Arduino as a hobby? If the latter, this section of the forum is probably not the best place to ask such a question.

Pieter

xd41efisc

At this point I would like something that works, so I can finish what I have started.
I am not fussed with it as a hobby, I have enough of them as it is.

The project I am using the Arduino on is my main hobby.
What I am doing is building a car alarm that interfaces with the factory immobilizer / keyless entry
system.

I have it working to an extent but not 100% to my liking.
I did not put this in the original post, because it may have confused the issue.

I have used a 555 timer on the input to get it closer to my liking, but was hoping that it could be done in the coding without using the 555.

I just need what was in the original post so, I can get an idea of what it involves, if it can be done at all.

Thanks.

PieterP

The LED also has to go HIGH the moment the button goes HIGH.
This also needs to use no delay.
What exactly do you mean here? Does 'HIGH' mean released or pressed?

xd41efisc

When I say HIGH I mean pressed in regards to the button, and ON (lit up) in regards to the LED.

PieterP

This is what I came up with:

xd41efisc

Thanks mate, but that did not work the way I need it to.

I need to think about this a bit more, to see if I can explain it better and give you a better idea of what
is needed.

Thanks.

PieterP

I think it would be easiest if you express your expectations in a graph like this:
Code: [Select]
 Button
     Released  ───┐  ┌───────────────┐
     Pressed      └──┘               └──────────────────────────────────────────────────

   LED
    On            ┌─┐ ┌─┐ ┌─┐        ┌─┐ ┌─┐ ┌─┐     ┌─┐ ┌─┐ ┌─┐     ┌─┐ ┌─┐ ┌─┐
    Off        ───┘ └─┘ └─┘ └────────┘ └─┘ └─┘ └─────┘ └─┘ └─┘ └─────┘ └─┘ └─┘ └────────

Go Up