that_one_nigga_you_k

tirando do sono profundo pelo clock

May 22nd, 2025
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <RTClib.h>
  3. #include "esp_sleep.h"
  4.  
  5. RTC_DS3231 rtc;
  6.  
  7. #define SDA_PIN 21
  8. #define SCL_PIN 22
  9. #define RTC_INT_PIN 33  // Pino que recebe o alarme
  10.  
  11. void setup() {
  12.   Serial.begin(115200);
  13.   delay(2000);
  14.  
  15.   Wire.begin(SDA_PIN, SCL_PIN);
  16.  
  17.   if (!rtc.begin()) {
  18.     Serial.println("RTC não encontrado!");
  19.     while (1);
  20.   }
  21.  
  22.   if (rtc.lostPower()) {
  23.     Serial.println("Ajustando data/hora.");
  24.     rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  25.   }
  26.  
  27.   // Limpa alarmes anteriores
  28.   rtc.clearAlarm(1);
  29.   rtc.clearAlarm(2);
  30.  
  31.   // Desativa saída de onda quadrada
  32.   rtc.writeSqwPinMode(DS3231_OFF);
  33.  
  34.   // Configura alarme para 10 segundos à frente
  35.   DateTime now = rtc.now();
  36.   DateTime alarmTime = now + TimeSpan(0, 0, 0, 30);  // +10 segundos
  37.  
  38.   rtc.setAlarm1(alarmTime, DS3231_A1_Second);  // Alarme dispara quando segundos coincidem
  39.  
  40.   Serial.print("Alarme marcado para: ");
  41.   Serial.println(alarmTime.timestamp());
  42.  
  43.   // Configura GPIO para acordar com nível baixo
  44.   pinMode(RTC_INT_PIN, INPUT_PULLUP);
  45.   esp_sleep_enable_ext0_wakeup((gpio_num_t)RTC_INT_PIN, 0);
  46.  
  47.   Serial.println("Dormindo (deep sleep)...");
  48.   delay(1000);
  49.  
  50.   esp_deep_sleep_start();
  51. }
  52.  
  53. void loop() {
  54.   // Nunca entra aqui
  55. }
  56.  
Add Comment
Please, Sign In to add comment