Sei sulla pagina 1di 3

#include <LiquidCrystal.

h>
#include <Keypad.h>//Libreria para Teclado
//Inicio LCD
const int rs = 33, rw = 35, en = 31, d4 = 29, d5 = 27, d6 = 25, d7 = 23;
//Constantes para la LCD
//LiquidCrystal(rs, rw, enable, d4, d5, d6, d7)
LiquidCrystal lcd(rs, rw, en, d4, d5, d6, d7);
//Fin configuracion LCD
//Configuracion Teclado
const byte filas = 4; //four rows
const byte columnas = 4; //three columns
byte pinsFilas[filas] = {22, 24, 26, 28}; //connect to the row pinouts of the
keypad
byte pinsColumnas[columnas] = {30, 32, 34, 36}; //connect to the column pinouts of
the keypad

char teclas[filas][columnas] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

Keypad teclado = Keypad( makeKeymap(teclas), pinsFilas, pinsColumnas, filas,


columnas );
// Fin configuracion para teclado

//bufer::::::::::
#define DEBUG_ARRAY(a) {for (int index = 0; index < sizeof(a) / sizeof(a[0]);
index++) {Serial.print(a[index]); Serial.print('\t');} Serial.println();};
String str = "";
const char separator = ',';
const int dataLength = 4;
float data[dataLength];
///////////////////
//#####Alcohol######
int alc;
float volt, Rs1;
double alco;
///////////////////
char k;
void setup() {
Serial.begin(115200);
lcd.begin(16, 2);
lcd.print("MICROCONTROLADORES");
delay(500);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("PRACTICA WIFI");
delay(500);
}

void loop() {
//SERIAL...........................
if (Serial.available()) {
str = Serial.readStringUntil('\n');
for (int i = 0; i < dataLength ; i++) {
int index = str.indexOf(separator);
data[i] = str.substring(0, index).toFloat();
str = str.substring(index + 1);
}
}
///////////////
principal();
}

void principal() {
inicio:
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("U.T.A."); //Prendido de pantalla
delay (500);
lcd.setCursor(0, 1);
lcd.print("#SENSORES#");
delay (500);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("A:LDR B:GAS C:AL");
lcd.setCursor(0, 1);
lcd.print("D:TEM #:HUM");
//SERIAL WIFI
Serial.print(0);
Serial.print(',');
Serial.print(0);
Serial.print(',');
Serial.print(0);
Serial.print(',');
Serial.println(0);
while (true) {
k = teclado.getKey();
if (k != 0) {
if (k == 'A') {
lcd.clear();
alcolimetro();
}
if (k == '*') {
lcd.clear();
goto inicio;
}
}
}
}
/*-------------------------------------------------*/
void alcolimetro() {
while (true) {
alc = analogRead(A0);
volt = alc * (5.0 / 1023.0);
Rs1 = 1000 * ((5 - volt) / volt);
alco = 0.4091 * pow(Rs1 / 5463, -1.497);
lcd.setCursor(0, 0);
lcd.print("S. Alcohol");
lcd.setCursor(0, 1);
lcd.print(volt);
lcd.setCursor(5, 1);
lcd.print("V");
lcd.setCursor(7, 1);
lcd.print(alco);
lcd.setCursor(12, 1);
lcd.print("mg/L");
//SERIAL WIFI
Serial.print(alco);
Serial.print(',');
Serial.print(0);
Serial.print(',');
Serial.print(0);
Serial.print(',');
Serial.println(0);
delay(200);
char k = teclado.getKey();
if (k == '*') {
principal();
}
}
}

Potrebbero piacerti anche