44 lines
1.2 KiB
C
44 lines
1.2 KiB
C
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include "pico/stdlib.h"
|
|
#include "hardware/gpio.h"
|
|
#include "hardware/irq.h"
|
|
|
|
#define BUTTON_PIN_ROW_1 16
|
|
#define BUTTON_PIN_COLUMN_1 18
|
|
#define LED_PIN 25
|
|
|
|
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_set_dir(BUTTON_PIN_COLUMN_1, GPIO_OUT);
|
|
gpio_set_dir(BUTTON_PIN_ROW_1, GPIO_IN);
|
|
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) {
|
|
sleep_ms(1000);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|