I hook it up to port 32 and use this code
Code: Select all
gpio_set_direction(GPIO_NUM_25, GPIO_MODE_OUTPUT);
gpio_set_direction(GPIO_NUM_32, GPIO_MODE_INPUT);
gpio_set_level(GPIO_NUM_25, 1);
int button_state = 1;
while (1) {
const int current_state = gpio_get_level(GPIO_NUM_32);
if (current_state == 0 && button_state == 1) {
// // If button is pressed
printf("Pressed");
button_state = 0;
// Turn the LED on
} else if(current_state == 1 && button_state == 0) {
button_state = 1;
// printf("Button Released");
}
vTaskDelay(1);
// Add 1 tick delay (10 ms) so that current task does not starve idle task and trigger watchdog timer
}
Also since this is my first time posting feel free to let me know if this is the wrong room.