#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const byte filas = 4;
const byte columnas = 4;
byte pinFilas[filas] = {2,3,4,5};
byte pinColumnas[columnas] = {6,7,8,9};
char teclas[filas][columnas] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','.','D'}
};
Keypad teclado = Keypad(makeKeymap(teclas), pinFilas, pinColumnas, filas, columnas);
LiquidCrystal_I2C lcd(0x27, 16, 2);
int i, count = 0;
String v, a;
float volt, amper, watts;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Ingrese voltaje");
}
void loop() {
volt = voltaje();
amper = amperes();
watts = volt * amper;
lcd.setCursor(0,0);
lcd.print("Watts obtenidos");
lcd.setCursor(0,1);
lcd.print(watts);
lcd.print(" [W]");
}
float voltaje(){
float voltios = 0.0;
while(count < 8){
char c = teclado.getKey(); //verifico si hay tecla
if(c >= '0' && c <= '9' || c == '.'){
v += c;
lcd.setCursor(0,0);
lcd.print("Ingrese voltaje");
lcd.setCursor(0,1);
lcd.print(v);
count++;
}
if(c == 'C'){
v = "";
lcd.clear();
delay(1000);
lcd.print("Ingrese voltaje");
lcd.setCursor(0,1);
count = 0;
}
if(c == 'A'){
voltios = v.toFloat();
v = "";
lcd.clear();
break;
}
}
return voltios;
}
float amperes(){
float amperios = 0.0;
lcd.setCursor(0,0);
lcd.print("Ingrese amperaje");
count = 0;
while(count < 8){
char c = teclado.getKey(); //verifico si hay tecla
if(c >= '0' && c <= '9' || c == '.'){
a += c;
lcd.setCursor(0,0);
lcd.print("Ingrese amperaje");
lcd.setCursor(0,1);
lcd.print(a);
count++;
}
if(c == 'C'){
a = "";
lcd.clear();
delay(1000);
lcd.print("Ingrese amperaje");
lcd.setCursor(0,1);
count = 0;
}
if(c == 'A'){
amperios = a.toFloat();
a = "";
lcd.clear();
break;
}
}
return amperios;
}