2026-06-09

button interactivity with the pico2

had to start somewhere with a basic circuit, and because the pico2 already has a built-in LED, i figured putting in a button and reading that for the LED was the best path forward:
the example code is here. i'm using interrupts to check if the button state rises/falls (i.e., changes), but i think the code can get a bit confused if the toggle happens quickly.

i think the only confusing part was not realizing i needed to set the GPIO to pull up (gpio_pull_up(BUTTON_PIN)); i was wondering if i had wired up the button wrong. this encouraged me to set the LED to default on (so pressing the button turns it off), so that at least i knew the board was powered up :/.

thanks to Ramji for a basic tutorial here, which helped me build out the C version, and the pico-examples for interrupts which made the code more "elegant" than just checking state and sleeping.

No comments:

Post a Comment