button work, but dont understand how read input from pin
This commit is contained in:
parent
42783e98e4
commit
2c547f642f
36
main.c
36
main.c
@ -1,3 +1,4 @@
|
|||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
#include "hardware/gpio.h"
|
#include "hardware/gpio.h"
|
||||||
@ -7,31 +8,36 @@
|
|||||||
#define BUTTON_PIN_COLUMN_1 18
|
#define BUTTON_PIN_COLUMN_1 18
|
||||||
#define LED_PIN 25
|
#define LED_PIN 25
|
||||||
|
|
||||||
void button_callback(uint pin);
|
void button_callback(uint gpio, uint32_t events);
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
stdio_init_all();
|
stdio_init_all();
|
||||||
|
printf("Starting\n");
|
||||||
gpio_init(BUTTON_PIN_ROW_1);
|
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_COLUMN_1, GPIO_OUT);
|
||||||
gpio_set_dir(BUTTON_PIN_ROW_1, GPIO_IN);
|
gpio_set_dir(BUTTON_PIN_ROW_1, GPIO_IN);
|
||||||
gpio_pull_up(BUTTON_PIN_ROW_1);
|
gpio_pull_up(BUTTON_PIN_COLUMN_1);
|
||||||
gpio_pull_up(BUTTON_PIN_ROW_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_init(LED_PIN);
|
||||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!gpio_get(BUTTON_PIN_ROW_1)) {
|
sleep_ms(1000);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user