Button Release detection?

I’ve been looking around, and can’t seem to find any code on how to do this seemingly easy thing - how do you check if a button has been depressed and released, and then run something only once the button has been released… I have one idea, but it seems way to complicated and won’t work for most applications… is there any way to do this easily?

Also, the button library doesn’t help with this, so don’t suggest that, unless I misuderstood how to use it, then you should be specific (give an example perhaps?)

-Thx :wink:

Assuming your button pulls an input pin low when you push the button, the following should work:

  currentState = digitalRead(switchPin);
  if (currentState != lastState) {
    if (currentState == LOW) {
      // button down event
    if (currentState == HIGH) {
      // button up event
    // debounce
  lastState = currentState;

Another approach (depending on exact needs) would be to use interrupt. Assign an interrupt and execute some code when Pin changes state :-).