Detecting RISING/FALLING digital input.

Any code or library to get boolean value when a digital input RISES or FALLS?

Thanks.

Are you familiar with attachInterrupts() call?

Or you can program yourself a polling mechanism and remember the last state and compare that to the new state of the pin.
4 outcomes possible:

  • RISING
  • FALLING
  • HIGH
  • LOW

The latter two are if there is no change, you can indicate the state itself (sometimes useful)

robtillaart:
Are you familiar with attachInterrupts() call?

I do know attachInterrups() call. Something like that is what I would like to use with the rest of digital pins, but without interruption, of course.

robtillaart:
Or you can program yourself a polling mechanism and remember the last state and compare that to the new state of the pin.

Actually this is the code I asked for! :slight_smile:

There are many examples of edge detection and I'm sure Google will show you more than you care to look at. Essentially, you need to remember the previous state and compare it with the new state to detect whether it has changed. Remember to update the previous state afterwards ready for the next iteration.

you might find this interesting - Arduino Playground - PinChangeInt -

Thanks a lot. All answers have been quite useful.