forked from jkroso/pico-button.c
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
18 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,31 @@ | ||
#include "pico/stdlib.h" | ||
#include <stdio.h> | ||
#include <button.h> | ||
#define BUTTON_PIN 21 | ||
#define PLAY_BUTTON 16 // Button on GPIO 16 | ||
#define PAUSE_BUTTON 17 // Button on GPIO 17 | ||
|
||
void onchange(button_t *button_p) { | ||
button_t *button = (button_t*)button_p; | ||
printf("Button on pin %d changed its state to %d\n", button->pin, button->state); | ||
|
||
if(button->state) return; // Ignore button release. Invert the logic if using | ||
// a pullup (internal or external). | ||
|
||
switch(button->pin){ | ||
case PLAY_BUTTON: | ||
printf("Play\n"); | ||
break; | ||
case PAUSE_BUTTON: | ||
printf("Pause\n"); | ||
break; | ||
} | ||
} | ||
|
||
int main() { | ||
stdio_init_all(); | ||
button_t *my_button = create_button(BUTTON_PIN, onchange); | ||
printf("Button created. Its state is %d\n", my_button->state); | ||
button_t *play_button = create_button(PLAY_BUTTON, onchange); | ||
button_t *pause_button = create_button(PAUSE_BUTTON, onchange); | ||
|
||
while (true) tight_loop_contents(); | ||
return 0; | ||
} |