A PushButton class

I have written a very simple class for push button handling for my needs, and want to share it GitHub - KillzoneKid/PushButton: A simple class to handle multiple push buttons. The usage is pretty straight forward

#include "PushButton.h"

#define button1pin 1 // change
#define button2pin 2 // change

// state 0 - released
// state 1 - pressed
// state 2 - pressed and held

PushButton button1 = PushButton(button1pin, [](ButtonState state, PushButton* button) { Serial.print("Button1 state: "); Serial.println(state); });
PushButton button2 = PushButton(button2pin, [](ButtonState state, PushButton* button) { Serial.print("Button2 state: "); Serial.println(state); });

void setup() 

void loop() 



Not seeing it

And now?


Ok then, it's probably me.

The normal way would be:

attachInterrupt(digitalPinToInterrupt(_pin) ...

For many boards there are only a few pins which are allowed. For the Arduino Uno/Nano/Mini/Mega pin 1 is RX [EDIT] TX (see post by TheMemberFormerlyKnownAsAWOL below).
But the "attachInterruptParam" is a undocumented lower level functions that is not available on most boards as far as I know. But I could be wrong. I don't even know if I'm allowed to reply in this topic.

why not use the Bounce2 library?


For UNO and NANO, there are only two DPins (2 and 3) which are allowed to be the argument of digitalPinToInterrupt(DPin) function.

Have another guess.

My sentiments as well. Does the Arduino world really need yet another switch library?

From observation and operation:
DPin-1 TX for UNO
DPin-1 TX0 for MEGA and DUE