Skip to content

Commit f4a732c

Browse files
committed
Added new widgets files
1 parent 3e62f41 commit f4a732c

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Ajustes de funciones
2+
//--------------------------------------------------------------------------
3+
const int NUM_MUESTRAS = 500; // Número de muestras (ajustable)
4+
const int TIEMPO_LECTURA = 100; // Duración de la lectura en milisegundos
5+
const int esperaUs = 100; // Espera entre cada medicion en microsegundos
6+
7+
float factorSensor = 30.0; // Factor del sensor (ajustable)
8+
float valorMinLecturaRMS = 0.25; // Valor mas bajo que se puede registrar. Para eliminar ruido.
9+
float factorAmplificador = 10; // Ajusta el valor según la amplificación del ccircuito de entrada
10+
11+
12+
13+
// Funcion para calcular la corriente RMS
14+
// ----- Similar a la utilizada en: https://naylampmechatronics.com/blog/51_tutorial-sensor-de-corriente-ac-no-invasivo-sct-013.html
15+
//--------------------------------------------------------------------------
16+
17+
18+
// Funcion 1: Toma una serie de lecturas mediante un ADC y devuelve el voltaje RMS. Tambien asigna el offset a la direccion de memoria indicada.
19+
//==================================================================
20+
float medirValorRMS(int pinSensor, float * voltajes, float &offset){
21+
long tiempoInicial = millis();
22+
23+
// Paso 1: Leer y guardar voltajes durante un tiempo específico
24+
int i = 0;
25+
while (millis() - tiempoInicial < TIEMPO_LECTURA && i < NUM_MUESTRAS) {
26+
voltajes[i] = analogRead(pinSensor) * (3.4 / 4096.0); // Conversión a voltaje
27+
i++;
28+
ets_delay_us(esperaUs);
29+
}
30+
31+
// Paso 2: Calcular el offset (promedio de los voltajes leídos)
32+
offset = 0;
33+
for (int j = 0; j < i; j++) {
34+
offset += voltajes[j];
35+
}
36+
offset /= i; // Offset promedio
37+
38+
// Paso 3: Calcular el RMS sin el offset
39+
float sumatoriaCuadrados = 0;
40+
for (int j = 0; j < i; j++) {
41+
float voltajeCorregido = voltajes[j] - offset;
42+
float corriente = voltajeCorregido * factorSensor; // Convertir voltaje a corriente
43+
sumatoriaCuadrados += sq(corriente);
44+
}
45+
float valorRMS = sqrt(sumatoriaCuadrados / i); // Calcular RMS
46+
47+
if(valorRMS<valorMinLecturaRMS) return 0; // Filtro de valores muy bajos
48+
return valorRMS;
49+
}
50+
51+
// Funcion 2: Utiliza la funcion 1 para adaptar el valor RMS a un valor de corriente equivalente segun el sensor
52+
//==================================================================
53+
float calcularCorrienteRMS(float &valorRMS, float &offset) {
54+
return valorRMS * (factorSensor/factorAmplificador); // convierte el valor de voltaje RMS medido a la corriente equivalente segun sensor
55+
}
56+
57+
58+
// Funcion 3: Calcula la frecuencia segun los datos.
59+
//==================================================================
60+
float calcularFrecuencia(float * voltajes, float offset, float period){
61+
// ... por hacer
62+
}
63+
64+
65+

src/widgets/osciloscopeWidget.h

Whitespace-only changes.

src/widgets/timeFuntions.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
// Para el tiempo
3+
//-------------------------------------
4+
#include <ESP32Time.h>
5+
6+
//ESP32Time rtc; // Horario sin desplazamiento
7+
ESP32Time rtc(-3600*6); // Horario -6 UTC de Costa Rica
8+
9+
void setCurrentInternalTime() {
10+
//
11+
rtc.setTime(30, 24, 15, 17, 1, 2021); // 17th Jan 2021 15:24:30
12+
}
13+
14+
void getCurrentInternalTime() {
15+
//
16+
Serial.println(rtc.getTime("RTC0: %A, %B %d %Y %H:%M:%S")); // (String) returns time with specified format
17+
Serial.println(rtc.getLocalEpoch()); // (unsigned long) epoch without offset, same for all instances
18+
19+
20+
// Serial.println(rtc.getTime()); // (String) 15:24:38
21+
// Serial.println(rtc.getDate()); // (String) Sun, Jan 17 2021
22+
// Serial.println(rtc.getDate(true)); // (String) Sunday, January 17 2021
23+
// Serial.println(rtc.getDateTime()); // (String) Sun, Jan 17 2021 15:24:38
24+
// Serial.println(rtc.getDateTime(true)); // (String) Sunday, January 17 2021 15:24:38
25+
// Serial.println(rtc.getTimeDate()); // (String) 15:24:38 Sun, Jan 17 2021
26+
// Serial.println(rtc.getTimeDate(true)); // (String) 15:24:38 Sunday, January 17 2021
27+
//
28+
// Serial.println(rtc.getMicros()); // (long) 723546
29+
// Serial.println(rtc.getMillis()); // (long) 723
30+
// Serial.println(rtc.getEpoch()); // (long) 1609459200
31+
// Serial.println(rtc.getSecond()); // (int) 38 (0-59)
32+
// Serial.println(rtc.getMinute()); // (int) 24 (0-59)
33+
// Serial.println(rtc.getHour()); // (int) 3 (1-12)
34+
// Serial.println(rtc.getHour(true)); // (int) 15 (0-23)
35+
// Serial.println(rtc.getAmPm()); // (String) pm
36+
// Serial.println(rtc.getAmPm(true)); // (String) PM
37+
// Serial.println(rtc.getDay()); // (int) 17 (1-31)
38+
// Serial.println(rtc.getDayofWeek()); // (int) 0 (0-6)
39+
// Serial.println(rtc.getDayofYear()); // (int) 16 (0-365)
40+
// Serial.println(rtc.getMonth()); // (int) 0 (0-11)
41+
// Serial.println(rtc.getYear()); // (int) 2021
42+
}

src/widgets/timeWidget.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// En este archivo se incluyen los elementos para crear el widget de tiempo
2+
3+
#if(EasyOledUI_timeWidget)
4+
5+
6+
#include "timeFuntions.h" // Incluye las funciones y librerias requeridas para procesar el tiempo
7+
8+
9+
10+
11+
12+
13+
14+
#end if
15+
16+

0 commit comments

Comments
 (0)