hola buen día a todos, quería comentar un problema que estoy teniendo en un control de temperatura para un cultivo en casa en el cual uso un teclado 4x4, un sensor de temperatura DHT1, un relé para accionar un calentador y una pantalla SH1106 que permite la interacción del usuario con el sistema, he tenido problemas para que la pantalla funcione correctamente, en cierto punto del proyecto no encendía la pantalla utilizándola junto con el teclado 4X4, creo que era un problema con las librerías porque utilice el teclado sin librería ( en primera instancia había usado la librería keypad) y funciono correctamente, el problema que tengo actualmente es que después de haber seleccionado la temperatura deseada en el sistema, no puedo indicar en el código que me imprima un texto en la pantalla porque deja de funcionar todo el sistema(esto ocurre en el case 3 que hay en el void loop, en este caso tiene un texto corto que puse como prueba donde dice "temperatura optima" o "regulando temperatura" en función de la temperatura deseada) la pantalla no muestra nada se queda congelada con el texto que le haya quedado cargado antes de subir el código y no lee el teclado. gracias de antemano, el código es el siguiente:
int etapa = 1;
char tecla;
char eleccion[15];
int prmTB,prmTA;
int rele=12;
#define releON 0
#define releOFF 1
byte pinesFilas[] = {9,8,7,6};
byte pinesColumnas[] = {5,4,3,2};
char teclas[4][4] = {{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}};
const unsigned char My_bitmap [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x60, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x40,
0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfb, 0xc8, 0x00, 0x00, 0x00, 0x0e,
0xf0, 0xc8, 0x00, 0x00, 0x00, 0x3f, 0x97, 0x28, 0x00, 0x00, 0x00, 0x3f, 0xe9, 0xac, 0x00, 0x00,
0x00, 0x7f, 0xf8, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xf0, 0x5d, 0x00, 0x00, 0x00, 0x7e, 0xff, 0x70,
0xc0, 0x00, 0x04, 0xf7, 0xff, 0xfe, 0x68, 0x00, 0x01, 0xf7, 0xff, 0xff, 0xf0, 0x00, 0x05, 0xbf,
0xff, 0xff, 0xf8, 0x00, 0x0b, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x06, 0x7f, 0xff, 0xff, 0xf8, 0x00,
0x0f, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x1f, 0xa7, 0xff, 0xff, 0xe0, 0x00, 0x3f, 0x1f, 0xff, 0xff,
0xc0, 0x00, 0x1f, 0x7f, 0xff, 0xfe, 0x00, 0x00, 0x0f, 0x8f, 0xff, 0xf2, 0x80, 0x00, 0x03, 0xff,
0xff, 0xc5, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x48, 0x4f, 0x20, 0x00, 0x00,
0x00, 0x00, 0x75, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x24, 0xff, 0x8c,
0x00, 0x00, 0x00, 0x00, 0x5b, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x3d, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x3f, 0xa5, 0x00, 0x00, 0x00, 0x1c, 0xbf, 0xf5, 0x00, 0x00, 0x00, 0x37, 0x3f, 0xb8, 0x00, 0x00,
0x00, 0x2f, 0xbf, 0x67, 0x80, 0x00, 0x00, 0x7f, 0xfd, 0xdd, 0x80, 0x00, 0x00, 0x7f, 0xbc, 0xff,
0x00, 0x00, 0x00, 0xfe, 0xfc, 0xa0, 0x00, 0x00, 0x00, 0xfe, 0x5e, 0xe0, 0x00, 0x00, 0x00, 0x0e,
0x4c, 0xe0, 0x00, 0x00, 0x00, 0x0e, 0x7d, 0xe0, 0x00, 0x00, 0x00, 0x0e, 0xff, 0xe0, 0x00, 0x00,
0x00, 0x06, 0xf9, 0xe0, 0x00, 0x00, 0x00, 0x03, 0xbf, 0x80, 0x00, 0x00, 0x00, 0x13, 0xff, 0x80,
0x00, 0x00, 0x00, 0x17, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x80, 0x00, 0x00, 0x00, 0x03,
0xf7, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x1f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xfa, 0x00, 0x00, 0x00, 0x00, 0x2f, 0xfc, 0x00,
0x00, 0x00, 0x00, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf4, 0x00, 0x00, 0x00, 0x00, 0x0f,
0xec, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xe4, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xe0, 0x00, 0x00, 0x00,
0x00, 0x0f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0b, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01,
0x40, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00
};
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include "DHT.h"
#define DHTPIN 10
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#define OLED_RESET 0
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup()
{
for (int nL = 0; nL <= 3; nL++) {
pinMode(pinesFilas[nL], OUTPUT);
digitalWrite(pinesFilas[nL], HIGH);
}
for (int nC = 0; nC <= 3; nC++) {
pinMode(pinesColumnas[nC], INPUT_PULLUP);
}
Serial.begin(9600);
Wire.begin();
dht.begin();
display.begin( 0X3C, true);
display.clearDisplay(); //for Clearing the display
display.display();
display.clearDisplay(); //for Clearing the display
display.drawBitmap(0, 0, My_bitmap, 42, 64, SH110X_WHITE);
display.setTextSize(1);
display.setTextColor(SH110X_WHITE);
display.setCursor(50, 8);
display.print("CONTROL DE");
display.setCursor(50, 22);
display.print("TEMPERATURA");
display.setTextSize(2);
display.setCursor(48, 36);
display.print("HONGOS");
display.display();
delay(400);
display.clearDisplay();
pinMode(rele, OUTPUT);
digitalWrite(rele,releOFF);
}
void loop(){
switch (etapa)
{
case 1:
display.clearDisplay(); //for Clearing the display
display.setTextSize(1);
display.setCursor(9, 2);
display.print("SELECCIONE EL RANGO");
display.setCursor(10, 12);
display.print("TEMPERATURA DESEADA");
display.setCursor(25, 24);
display.print("1. INOCULACION");
display.setCursor(25, 36);
display.print("2. COLONIZACION");
display.setCursor(25, 48);
display.print("3. FRUCTIFICACION");
display.display();
display.clearDisplay();
teclado();
if(tecla == '1' || tecla == '2' || tecla == '3' ){
etapa = 2;
}
break;
case 2:
if(tecla == '1')
{
strcpy(eleccion, "INOCULACION");
prmTB=26;
prmTA=28;
display.clearDisplay(); //for Clearing the display
display.setTextSize(1);
display.setCursor(9, 2);
display.print("SELECCIONE EL RANGO");
display.setCursor(10, 12);
display.print("TEMPERATURA DESEADA");
display.setCursor(6, 24);
display.print(">>>1. INOCULACION");
display.setCursor(25, 36);
display.print("2. COLONIZACION");
display.setCursor(25, 48);
display.print("3. FRUCTIFICACION");
display.display();
display.clearDisplay();
}
else if(tecla == '2')
{
strcpy(eleccion, "COLONIZACION");
prmTB=24;
prmTA=26;
display.clearDisplay(); //for Clearing the display
display.setTextSize(1);
display.setCursor(9, 2);
display.print("SELECCIONE EL RANGO");
display.setCursor(10, 12);
display.print("TEMPERATURA DESEADA");
display.setCursor(25, 24);
display.print("1. INOCULACION");
display.setCursor(6, 36);
display.print(">>>2. COLONIZACION");
display.setCursor(25, 48);
display.print("3. FRUCTIFICACION");
display.display();
display.clearDisplay();
}
else if(tecla == '3')
{
strcpy(eleccion, "FRUCTIFICACION");
prmTB=20;
prmTA=25;
display.clearDisplay(); //for Clearing the display
display.setTextSize(1);
display.setCursor(9, 2);
display.print("SELECCIONE EL RANGO");
display.setCursor(10, 12);
display.print("TEMPERATURA DESEADA");
display.setCursor(25, 24);
display.print("1. INOCULACION");
display.setCursor(25, 36);
display.print("2. COLONIZACION");
display.setCursor(6, 48);
display.print(">>>3. FRUCTIFICACION");
display.display();
display.clearDisplay();
}
if (tecla == 'D')
{
display.clearDisplay(); //for Clearing the display
display.setTextSize(1);
display.setCursor(35, 2);
display.print("SELECCIONO");
display.setCursor(20, 12);
display.print("TEMPERATURA DE");
display.setCursor(28, 24);
display.print(eleccion);
display.setCursor(20, 38);
display.print("PRESIONE * PARA");
display.setCursor(40, 50);
display.print("CAMBIAR");
display.display();
display.clearDisplay();
delay(2000);
etapa=3;
}
teclado();
break;
case 3:
if(tecla == 'A')
{
etapa=1;
}
float humidity = dht.readHumidity();
// Read temperature as Celsius (the default)
float tempC = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float tempF = dht.readTemperature(true);
Serial.println(tempC);
if((tempC > prmTB && tempC<=prmTA)||tempC>prmTA)
{
display.clearDisplay(); //for Clearing the display
display.setTextSize(1);
display.setCursor(9, 2);
display.print("TEMPERATURA");
display.setCursor(10, 12);
display.print("OPTIMA");
display.display();
delay(2000);
display.clearDisplay();
digitalWrite(rele, releOFF);
delay(150);
}
else
{
display.clearDisplay(); //for Clearing the display
display.setTextSize(1);
display.setCursor(9, 2);
display.print("REGULANDO");
display.setCursor(10, 12);
display.print("TEMPERATURA ");
display.display();
delay(2000);
display.clearDisplay();
digitalWrite(rele, releON);
delay(150);
}
teclado();
break;
}
}
void teclado()
{
//Barrido por las filas
for (int nL = 0; nL <= 3; nL++)
{
digitalWrite(pinesFilas[nL], LOW);
//Barrido en columnas buscando un LOW
for (int nC = 0; nC <= 3; nC++) {
if (digitalRead(pinesColumnas[nC]) == LOW)
{
//Serial.print("Tecla: ");
//Serial.println(teclas[nL][nC]);
tecla=teclas[nL][nC];
while(digitalRead(pinesColumnas[nC]) == LOW){}
}
}
digitalWrite(pinesFilas[nL], HIGH);
}
delay(10);
}
escribe o pega el código aquí