Button Logic!!

I'm working on a project with a button and I'd like to treat it similar to web events. I'd like to track things like... press down, release, and hold for X time. The first two are easy, but I'm having a tricky time figuring out how to handle the hold time and preventing the release of the hold form triggering another action.Xvideos Xnxx Chaturbate

Has anyone else done this? I'm hoping someone could walk me through the psuedo code or explain the logic in separating the events. I'm thinking there's something really simple that I'm just missing here, but for some reason, I am definitely missing it.

When the button becomes pressed, you start a millis() based timer (record the start time). Next you can check the duration that the button was pressed by subtracting the start time from the current time (millis()).

When working with a mechanical button, there will be some noise as the button bounces on making contact.

You will want to look at the state of the button as close to the initial falling edge as possible, and then lock-out looking for the bounce period. This is easy to do for the falling edge and rising edge, as long as the button is not released within the bounce period. Once you have successfully coded to trigger an event on both the falling and rising edge, in that even you can take one timestamp on the falling trigger and one on the rising trigger and subtract the later from the former. If you are using a pull-down resistor, and your button is pulling the port high, your waveform will look a bit like a top hat. It will look inverted if you are using a pull-up resistor and pulling the port low with the button press.