/* Interrupt Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
const uint8_t InterruptPin = 13;
bool Request;
bool deb;
volatile uint32_t last_interrupt_time = 0;
void IRAM_ATTR isr() {
uint32_t current_time = xTaskGetTickCountFromISR(); // Tempo atual (ticks)
// Debounce simples: ignora interrupções muito próximas (<200ms)
if (current_time - last_interrupt_time > pdMS_TO_TICKS(150)) {
Serial.println("Interrupt Request Received!");
Request = true;
last_interrupt_time = current_time;
}
/*
static uint64_t last_reset_time = 0;
static uint64_t press_start_time = 0;
static bool button_pressed = false;
uint64_t now = esp_timer_get_time();
if (now - last_reset_time < 100000) return;
last_reset_time = now;
if (!button_pressed) {
// Botão pressionado (borda de descida)
press_start_time = now;
ESP_EARLY_LOGI(TAG, "Botão de reset pressionado");
} else {
// Botão solto (borda de subida)
if ((now - press_start_time) < LONG_PRESS_TIME) {
ESP_EARLY_LOGW(TAG, "Reset rápido: Reiniciando ESP...");
esp_restart();
} else {
ESP_EARLY_LOGW(TAG, "Reset longo: Configurando NVS e reiniciando...");
nvs_manager_save_must_provision(1);
esp_restart();
}
}
button_pressed = !button_pressed;
*/
}
void setup() {
Serial.begin(9600);
pinMode(InterruptPin, INPUT_PULLUP);
attachInterrupt(InterruptPin, isr, FALLING );
deb = true;
}
void loop() {
if (Request){
deb = !deb;
Serial.println(deb);
Request = false;
// delay(500);
}
}
// // Variables will change:
// int lastSteadyState = LOW; // the previous steady state from the input pin
// int lastFlickerableState = LOW; // the previous flickerable state from the input pin
// int currentState; // the current reading from the input pin
// unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
// void setup() {
// // initialize serial communication at 9600 bits per second:
// Serial.begin(9600);
// // initialize the pushbutton pin as an pull-up input
// // the pull-up input pin will be HIGH when the switch is open and LOW when the switch is closed.
// pinMode(BUTTON_PIN, INPUT_PULLUP);
// }
// void loop() {
// // read the state of the switch/button:
// currentState = digitalRead(BUTTON_PIN);
// if (currentState != lastFlickerableState) {
// // reset the debouncing timer
// lastDebounceTime = millis();
// // save the the last flickerable state
// lastFlickerableState = currentState;
// }
// if ((millis() - lastDebounceTime) > DEBOUNCE_TIME) {
// // whatever the reading is at, it's been there for longer than the debounce
// // delay, so take it as the actual current state:
// // if the button state has changed:
// if(lastSteadyState == HIGH && currentState == LOW)
// Serial.println("The button is pressed");
// else if(lastSteadyState == LOW && currentState == HIGH)
// Serial.println("The button is released");
// // save the the last steady state
// lastSteadyState = currentState;
// }
// }