diff --git a/main.c b/main.c index 9e7017f..d30c267 100644 --- a/main.c +++ b/main.c @@ -1,3 +1,4 @@ +#include #include #include "pico/stdlib.h" #include "hardware/gpio.h" @@ -7,31 +8,36 @@ #define BUTTON_PIN_COLUMN_1 18 #define LED_PIN 25 -void button_callback(uint pin); +void button_callback(uint gpio, uint32_t events); int main() { stdio_init_all(); + printf("Starting\n"); gpio_init(BUTTON_PIN_ROW_1); - gpio_init(BUTTON_PIN_COLUMN_1); + //gpio_init(BUTTON_PIN_COLUMN_1); gpio_set_dir(BUTTON_PIN_COLUMN_1, GPIO_OUT); gpio_set_dir(BUTTON_PIN_ROW_1, GPIO_IN); - gpio_pull_up(BUTTON_PIN_ROW_1); - gpio_pull_up(BUTTON_PIN_ROW_1); + gpio_pull_up(BUTTON_PIN_COLUMN_1); + gpio_set_irq_enabled(BUTTON_PIN_ROW_1, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true); + gpio_set_irq_callback(&button_callback); + irq_set_enabled(IO_IRQ_BANK0, true); + //gpio_set_irq_enabled_with_callback(BUTTON_PIN_ROW_1, GPIO_IRQ_EDGE_FALL | GPIO_IRQ_EDGE_RISE, true, &button_callback); gpio_init(LED_PIN); gpio_set_dir(LED_PIN, GPIO_OUT); while (true) { - if (!gpio_get(BUTTON_PIN_ROW_1)) { - gpio_put(LED_PIN, 0); - // printf("ROW: %i\n", gpio_get(BUTTON_PIN_ROW_1)); - // printf("COLUMN: %i\n", gpio_get(BUTTON_PIN_COLUMN_1)); - } else { - gpio_put(LED_PIN, 1); - // printf("ROW: %i\n", gpio_get(BUTTON_PIN_ROW_1)); - // printf("COLUMN: %i\n", gpio_get(BUTTON_PIN_COLUMN_1)); - } + sleep_ms(1000); } } -void button_callback(uint pin){ - +void button_callback(uint gpio, uint32_t events){ + gpio_acknowledge_irq(gpio, events); + if(gpio == BUTTON_PIN_ROW_1){ + if (events == GPIO_IRQ_EDGE_RISE){ + gpio_put(LED_PIN, true); + printf("irq is happend \n"); + } + else{ + gpio_put(LED_PIN, false); + } + } }