Hola que tal... el proyecto es sencillo se trata simplemente de un termostato que enciende y apaga una resistencia dependiendo de lo que se necesite.
El menu y los sub-menus asi como las variables funcionan bien, el unico problema que tengo ahora es en la pantalla Splash, que es la que despues de algun tiempo se muestra por default en la LCD.
Aqui el codigo completo;
//=====================================LIBRERIAS==================================================//
#include <OneWire.h>
#include <dht.h> //Libreria para DTH
#include <DallasTemperature.h> //Libreria Ds1820
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h> //Libreria IC2
#include <buttons.h>
#include <MENWIZ.h>
#include <EEPROM.h>
//=====================================COSNTRUCTORES =============================================//
// DEFINE ARDUINO PINS FOR THE NAVIGATION BUTTONS
#define UP_BUTTON_PIN 9
#define DOWN_BUTTON_PIN 10
#define LEFT_BUTTON_PIN 7
#define RIGHT_BUTTON_PIN 8
#define CONFIRM_BUTTON_PIN 12
#define ESCAPE_BUTTON_PIN 11
dht DHT; //constructor del objeto
#define DHT11_PIN 5 // Pin sensor DTH
#define ONE_WIRE_BUS 2 //Pin Sensor temperatura
OneWire oneWire(ONE_WIRE_BUS); //define un bus para comunicarse con cualquier sensor
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
DeviceAddress insideThermometer; // arrays to hold device address
menwiz menu;
//Constructor objeto LCD
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
//=====================================GLOBAL VARIABLES==============================================//
float ti = 19.00;
float tf = 25.00;
const byte led =13; //led to chek if the heating element has staring
const byte rele = 4; //pin to start or stop heating element
int humidity = 0; //read the humidity sensor
float tempC = 0; //read the sensor temperature
float tempF = 0; //farenheit
//=====================================VOID SET UP ==================================================//
void setup(void)
{
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(led, OUTPUT);
//-----------------------------------MENWIZ MENU-------------------------------------------------//
_menu *r,*s1,*s2;
_var *v;
int mem;
// inizialize the menu object (16 colums x 2 rows)
menu.begin(&lcd,16,2);
//create the menu tree
r=menu.addMenu(MW_ROOT,NULL,F("MENU")); //create a root menu at first (required)
s1=menu.addMenu(MW_SUBMENU,r,F("AJUSTE TEMPER"));
s2=menu.addMenu(MW_VAR,s1,F("TEMP INCIO")); //add a terminal node (that is "variable");
s2->addVar(MW_AUTO_FLOAT,&ti,20.00,50.00,0.5); //create a variable of type "float number"...
s2=menu.addMenu(MW_VAR,s1,F("TEMP FINAL")); //add a terminal node (that is "variable");
s2->addVar(MW_AUTO_FLOAT,&tf,20.00,50.00,0.5); //create a variable of type "float number"...
menu.addUsrScreen(msc,10000);
menu.navButtons(UP_BUTTON_PIN,DOWN_BUTTON_PIN,ESCAPE_BUTTON_PIN,CONFIRM_BUTTON_PIN);
//-----------------------------------SENSOR DS1820-------------------------------------------------//
// locate devices on the bus
sensors.begin();
Serial.print(sensors.getDeviceCount(), DEC);
//Linea para debug
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
Serial.print("Device 0 Address: ");
//Funcion para imprimir la direccion del dispositivo --printAddress(insideThermometer);
// set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
sensors.setResolution(insideThermometer, 10);
}
//=====================================VOID LOOP ==================================================//
void loop(void){
menu.draw();
if (tempC < tf){ //Chek if the temperature is below the off heating element
digitalWrite(rele, LOW);
digitalWrite( led, ON);
}
if (tempC > ti){
digitalWrite(rele, HIGH); //chek if the temperature is above the start temperature
digitalWrite (led, OFF);
}
sensors.requestTemperatures(); // Comando para obtener temperatura
// It responds almost immediately. Let's print out the data
printTemperature(insideThermometer); // Use a simple function to print out the data
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void msc();
EL PROBLEMA ESTA AQUI
///////////////////////////////////////////////////////////////////////////////////////////////////
// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress){
tempC = sensors.getTempC(deviceAddress);
tempF = DallasTemperature::toFahrenheit(tempC); // Converts tempC to Fahrenheit
Serial.print("Temp C: ");
Serial.print(tempC);
Serial.print(" Temp F: ");
Serial.println(tempF);
}
Y es que en donde va ese problemin, el ejemplo maneja algo asi;
void msc(){
static char buf[7];
strcpy(menu.sbuf,"User screen"); //1st lcd line
strcat(menu.sbuf,"\nUptime (s): ");strcat(menu.sbuf,itoa((int)(millis()/1000),buf,10));//2nd lcd line
strcat(menu.sbuf,"\nFree mem : ");strcat(menu.sbuf,itoa((int)menu.freeRam(),buf,10));//3rd lcd line
strcat(menu.sbuf,"\n"); //4th lcd line (empty)
menu.drawUsrScreen(menu.sbuf);
}
Donde strcat es una funcion para concatener strings
strcpy es una funcion para copiar strings
itoa es una funcion para convertir numeros a strings Aqui
la cuestion es que estoy usando dos floats para la temperatura de inicio y final y aparentemente no estan soportados directamente por itoa... ya que el compilador me da un error...
Intente imprimirlo directamente en la LCD;
static char buf[10];
lcd.setCursor(0,0); lcd.print(tempC);lcd.print(" C"); lcd.print("HUMEDAD");
lcd.setCursor(0,1); lcd.print(tempF);lcd.print(" F"); lcd.print(humidity);
menu.drawUsrScreen(menu.sbuf);
Y funciona pero no se actualiza conforme la temperatura sube... Por lo que me imagino que debo convertir el float a un string y usar la funciones de arriba mencionadas, o el float a un array Aqui
La pregunta seria... cual es el mejor camino para hacer esto?
la pantalla se actualiza con algun cambio dentro de los arrays?
Gracias.
-Alex