Install with clib(1):
$ clib install jkroso/pico-button.c
create_button(pin, onchange)
: It will set the pin to pull up. It returns a button_t
struct
typedef struct button_t {
uint8_t pin;
bool state;
void (*onchange)(struct button_t *button);
} button_t;
#include "pico-button/button.c"
void onchange(button_t *button_p) {
button_t *button = (button_t*)button_p;
printf("Button on pin %d changed state to %d\n", button->pin, button->state);
}
int main() {
stdio_init_all();
button_t *b = create_button(21, onchange);
printf("Button created and it's state is %d\n", b->state);
while (true) tight_loop_contents();
return 0;
}