#include <LiquidCrystal.h>
unsigned long suma_pot = 0;
unsigned long suma_nivel = 0;
unsigned long muestras = 0;
int potenciometro = 0;
unsigned long tiempo_lectura = 0;
unsigned long tiempo_muestreo = 100;
LiquidCrystal lcd(12,13,17,16,27,14);
void setup() {
lcd.begin(16, 2);
ledcAttach(26, 1000,12); //Se configura el PWM //frecuencia 1KHz y resolucion 2^12
}
void loop() {
suma_pot += analogRead(39);
muestras++;
if (millis()>tiempo_lectura) {
tiempo_lectura += tiempo_muestreo;
potenciometro = suma_pot / muestras;
suma_pot = 0;
muestras = 0;
ledcWrite(26,potenciometro);
lcd.setCursor(0,0);
float tension = potenciometro * 15.0 / 4093;
lcd.print(tension);
}
}