Actividad 3

 

Configurar y obtener datos del RTC

Esta actividad consiste en configurar la hora del Reloj en Tiempo Real interno del ESP32 y mostrar la hora y la fecha constantemente por el monitor serial. Para completar el ejercicio no necesitarás componentes adicionales ni hacer montajes, solamente la Placa de desarrollo NodeMCU conectada al ordenador utilizando el cable USB del Kit.

// Incluimos las librerías necesarias
#include <ESP32Time.h>

// Crear instancia del objeto RTC del ESP32
ESP32Time rtc;

void setup() {

    // Inicializar monitor Serial
    Serial.begin(9600);
    // Configurar fecha y hora en el RTC interno del ESP32
    rtc.setTime(0, 0, 8, 1, 1, 2024);

}

void loop() {

    // Obtener fecha
    int dia = rtc.getDay();
    int mes = rtc.getMonth();
    int anio = rtc.getYear();

    // Obtener hora
    int hora = rtc.getHour(true);
    int minuto = rtc.getMinute();
    int segundo = rtc.getSecond();
    int millisegundo = rtc.getMillis();

    // Preparar mensaje para mostrar por pantalla la fecha y la hora
    String fecha = "Fecha: " + String(dia) + "/" + String(mes) + "/" + String(anio);
    String tiempo = "Hora: " + String(hora) + ":" + String(minuto) + ":";
    tiempo += String(segundo) + "," + String(millisegundo);

    // Mostrar información por monitor serial
    Serial.println(fecha);
    Serial.println(tiempo);

    delay(250);

}
Vistas
0 Número de vistas
0 Vistas de miembros
0 Vistas públicas
Acciones
0 Gustos
0 No me gusta
0 Comentarios
Compartir en redes sociales
Compartir enlace
Compartir por correo

Por favor iniciar sesión para compartir esto webpage por correo.