Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <RTClib.h>
- #include "esp_sleep.h"
- RTC_DS3231 rtc;
- #define SDA_PIN 21
- #define SCL_PIN 22
- #define RTC_INT_PIN 33 // Pino que recebe o alarme
- void setup() {
- Serial.begin(115200);
- delay(2000);
- Wire.begin(SDA_PIN, SCL_PIN);
- if (!rtc.begin()) {
- Serial.println("RTC não encontrado!");
- while (1);
- }
- if (rtc.lostPower()) {
- Serial.println("Ajustando data/hora.");
- rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- }
- // Limpa alarmes anteriores
- rtc.clearAlarm(1);
- rtc.clearAlarm(2);
- // Desativa saída de onda quadrada
- rtc.writeSqwPinMode(DS3231_OFF);
- // Configura alarme para 10 segundos à frente
- DateTime now = rtc.now();
- DateTime alarmTime = now + TimeSpan(0, 0, 0, 30); // +10 segundos
- rtc.setAlarm1(alarmTime, DS3231_A1_Second); // Alarme dispara quando segundos coincidem
- Serial.print("Alarme marcado para: ");
- Serial.println(alarmTime.timestamp());
- // Configura GPIO para acordar com nível baixo
- pinMode(RTC_INT_PIN, INPUT_PULLUP);
- esp_sleep_enable_ext0_wakeup((gpio_num_t)RTC_INT_PIN, 0);
- Serial.println("Dormindo (deep sleep)...");
- delay(1000);
- esp_deep_sleep_start();
- }
- void loop() {
- // Nunca entra aqui
- }
Add Comment
Please, Sign In to add comment