/*
**** MULTIMETRO CON INDICADOR LED Y LATIDO DE ON****
1.- Medir Voltaje en A0
2.- Colocar 5 leds entre D2 y D5
3.- Colocar un Switch en D8
4.- Establecer un tiempo de Backlight de 30 Segudos, reseteables
con botos SW
5.- Chequeo Inicial de encendido de todos los Leds
6.- Indicadores LED:
Rojo <= 2V
Amarillo entre 2 y 4V
Verde > a 4V
7.- NO USAR DELAY EN EL LOOP
EXITOOOO!!!!!
*/
#include
<LiquidCrystal_I2C.h> //Carga Libreria
LiquidCrystal_I2C lcd(0x27, 20, 4); // Inicializa Display
#define Led_Verde 2
#define Led_Amarillo 3
#define Led_Rojo 4
#define Led_Azul 5
#define SW 8
//
Variables de tiempo para Backlight
unsigned long BKL_Inicio = 0;
int
BKL_Tiempo = 20000; // Tiempo encendido Backlight Display
//
Variables de tiempo para Latido
int
Tiempo; //Para Latido
int
Tiempo_anterior; //Para Latido
int
Estado; // Para Latido
//
Variables para Voltímetro
float Lectura_1 = 0;
float Volt_1;
float Medida_1 = 0;
int
Cuentas = 100;
void setup() {
//Inicialización Display
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("BRAIN NASER");
lcd.setCursor (3, 1);
lcd.print("VOLTIMETRO DC");
lcd.setCursor (3, 3);
lcd.print("Bienvenido...");
// pinMode
pinMode (SW, INPUT);
pinMode(A0, INPUT);
for (int Led = 2; Led <= 5; Led++) {
pinMode (Led, OUTPUT);
}
// Chequeo Inicial de Encendido Leds
for (int Led = 2; Led <= 5; Led++) {
digitalWrite (Led, HIGH);
delay (500);
}
delay (2000); // Deja 2 segundos todos los leds encendidos
// Apagado de Leds y limpiar pantalla
lcd.clear();
for (int Led = 2; Led <= 5; Led++) {
digitalWrite (Led, LOW); // Apaga todos los leds
}
//delay (1000);
}
void loop() {
Latido_ON();
Switch();
med_Voltios();
Medidor_Led();
}
/////////// LATIDO /////////
void Latido_ON() {
Tiempo = millis();
if ((Tiempo - Tiempo_anterior) >= 5 && (Estado == 0)) {
Estado = !Estado;
digitalWrite (Led_Azul, 0);
Tiempo_anterior = millis();
}
if ((Tiempo - Tiempo_anterior) >= 3000 && Estado == 1) {
Estado = !Estado;
digitalWrite (Led_Azul, 1);
Tiempo_anterior = millis();
}
}
/////////// SWITCH /////////
void Switch() {
if (digitalRead (SW) == LOW) {
BKL_Inicio = millis();
}
if ((millis() - BKL_Inicio) <= BKL_Tiempo) {
lcd.backlight();
}
else {
lcd.noBacklight();
}
}
/////////// VOLTIMETRO /////////
void med_Voltios() {
Lectura_1 = 0;
Volt_1 = 0;
Medida_1 = 0;
for (int B = 1; B <= Cuentas; B++) {
Lectura_1 = analogRead(A0);
Volt_1 = Volt_1 + Lectura_1;
}
Medida_1 = (((Volt_1 / Cuentas) * 5) / 1023);
lcd.setCursor(0, 0);
lcd.print("Fuente A0 = ");
lcd.print(Medida_1, 2);
lcd.print("V");
}
/////////// MEDIDOR LED /////////
void Medidor_Led() {
if (Medida_1 <= 2) {
digitalWrite (Led_Rojo, HIGH);
digitalWrite (Led_Amarillo, LOW);
digitalWrite (Led_Verde, LOW);
}
if (Medida_1 > 2 && Medida_1 <= 4) {
digitalWrite (Led_Rojo, HIGH);
digitalWrite (Led_Amarillo, HIGH);
digitalWrite (Led_Verde, LOW);
}
if (Medida_1 > 4 && Medida_1 <= 5) {
digitalWrite (Led_Rojo, HIGH);
digitalWrite (Led_Amarillo, HIGH);
digitalWrite (Led_Verde, HIGH);
}
}