//Includes
#include "ledController.h"
#include "display.h"
#include <DHT.h>
#include "poteController.h"
//Funciones
void mostrarMenu();
void mostrarOpcionesLED();
void mostrarOpcionesDHTPOTE();
#define LED 23
#define PIN_SENSOR 14
#define POTE 12
LedController ledController(LED);
Display myDisplay(128, 64, -1);
DHT sensor(PIN_SENSOR, DHT22);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LED, OUTPUT);
pinMode(POTE, INPUT);
sensor.begin();
myDisplay.init(0x3C);
myDisplay.showOutput("Hola");
mostrarMenu();
}
void loop() {
if (Serial.available()) {
int opcion = Serial.parseInt();
Serial.read();
int opcionLED = 0;
int opcionDHT = 0;
float temp;
float hum;
int valorPote;
float voltajePote;
switch (opcion) {
case 1:
mostrarOpcionesLED();
while (opcionLED != 3) {
if (Serial.available()) {
opcionLED = Serial.parseInt();
Serial.read();
switch (opcionLED) {
case 1:
ledController.turnOn();
break;
case 2:
ledController.turnOff();
break;
case 3:
mostrarMenu();
break;
default:
Serial.println("Opcion incorrecta.");
break;
}
}
}
break;
case 2:
mostrarOpcionesDHTPOTE();
while(opcionDHT != 2){
if(Serial.available()){
opcionDHT = Serial.parseInt();
Serial.read();
switch(opcionDHT){
case 1:
temp = sensor.readTemperature();
hum = sensor.readHumidity();
myDisplay.updateDisplayDHTData(temp, hum);
break;
case 2:
myDisplay.clearDisplay();
mostrarMenu();
break;
default:
Serial.println("Opcion incorrecta.");
}
}
}
delay(3000);
myDisplay.clearDisplay();
break;
case 3:
Serial.println("POTE");
mostrarOpcionesDHTPOTE();
while(opcionDHT != 2){
if(Serial.available()){
opcionDHT = Serial.parseInt();
Serial.read();
switch(opcionDHT){
case 1:
poteData = poteController.CalculatePote();
int ValorPote = poteData.ValorPote;
float voltajePote = poteData.voltajePote;
myDisplay.updateDisplayProte(ValorPote, voltajePote);
break;
case 2:
myDisplay.clearDisplay();
mostrarMenu();
break;
default:
Serial.println("Opcion incorrecta.");
}
}
}
}
}
}
void mostrarMenu() {
/*
Serial.println("Seleccione una opcion");
Serial.println("1. Encender LED.");
Serial.println("2. Leer humedad y temperatura del sensor DHT22");
Serial.println("3. Leer valor de potenciometro.");
*/
myDisplay.showOutput("Seleccione una opcion\n"
"1. Encender LED.\n"
"2. Leer humedad y temperatura del sensor DHT22\n"
"3. Leer valor de potenciometro.");
}
void mostrarOpcionesLED() {
/*
Serial.println("Seleccione una opcion: ");
Serial.println("1. Encender LED");
Serial.println("2. Apagar LED.");
Serial.println("3. Volver atras");
*/
myDisplay.showOutput("Seleccione una opcion: \n"
"1. Encender LED\n"
"2. Apagar LED.\n"
"3. Volver atras");
}
void mostrarOpcionesDHTPOTE() {
/*
Serial.println("Seleccione una opcion: ");
Serial.println("1. Tomar valores");
Serial.println("2. Volver atras");
*/
myDisplay.showOutput("Seleccione una opcion: \n"
"1. Tomar valores\n"
"2. Volver atras");
}