#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
const int BTN_PIN_R = 28;
const int BTN_PIN_G = 26;
const int LED_PIN_R = 4;
const int LED_PIN_G = 6;
volatile int g_flag_r = 0;
volatile int g_flag_g = 0;
void pin_init(void);
void btn_callback(uint gpio, uint32_t events) {
if (gpio == BTN_PIN_R) {
g_flag_r = 1;
} else if (gpio == BTN_PIN_G) {
g_flag_g = 1;
}
}
int main() {
stdio_init_all();
pin_init();
gpio_set_irq_enabled_with_callback(BTN_PIN_R,
GPIO_IRQ_EDGE_FALL,
true,
&btn_callback);
// Segunda IRQ usa callback já configurado.
gpio_set_irq_enabled(BTN_PIN_G,
GPIO_IRQ_EDGE_FALL,
true);
while (true) {
if(g_flag_r || g_flag_g) {
printf("IRQ 0: %d | IRQ 1: %d\n", g_flag_r, g_flag_g);
// clear flags
g_flag_r = 0;
g_flag_g = 0;
}
}
}
void pin_init(void){
gpio_init(BTN_PIN_R);
gpio_set_dir(BTN_PIN_R, GPIO_IN);
gpio_pull_up(BTN_PIN_R);
gpio_init(BTN_PIN_G);
gpio_set_dir(BTN_PIN_G, GPIO_IN);
gpio_pull_up(BTN_PIN_G);
}