I have a problem as with how to show the temperature all the time realtime on the lcd in the loop() with out it overwriting the menus when i need to use them , the menus are all working and i can change values via menu on the lcd to make my relays turn on and off at whatever temperature.
but the lcdHeader();
how do i make this function loop only when no keys on lcd keypad sheild have not been pressed unsure how to write it with millis() to compare the keybutton press time for say 5 seconds and if no buttons pressed in the time run the lcdheader() as that will be enough time i was in the menu and never pressed anykeys it will just all get overwriten by the lcdheader() function.
cheers in advance
the code://
#include <stdio.h>
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 3 on the Arduino
#define ONE_WIRE_BUS 3
#define TEMPERATURE_PRECISION 9
//Set LCD PINS
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
//The thermometers are identified by their unique identifier
byte insideThermometer[8] = { 0x28, 0x36, 0x6B, 0x3F, 0x03, 0x00, 0x00, 0x16 };
byte outsideThermometer[8] = { 0x28, 0x3B, 0x7B, 0x3F, 0x03, 0x00, 0x00, 0x20 };
// ===================================================================
// hardware settings
#define rightKey 0
#define upKey 1
#define downKey 2
#define leftKey 3
#define selectKey 4
#define NUM_KEYS 5
// ===================================================================
// Program parameters
#define minOpt1 5
#define maxOpt1 50
int valueOpt1 = 23;
#define minOpt2 8
#define maxOpt2 40
int valueOpt2 = 25;
#define programMode1 0
#define programMode2 1
#define programMode3 2
int programMode = programMode1;
boolean inMainProgram = false;
int programmSequence = 0;
#define sequenceModeSelect 0
#define sequenceModeOption 1
#define sequenceModeProgram 2
int pinTemp1 = 11;
int pinTemp2 = 12;
// first menu line - description of menu level
char sequenceHeader[3][17] = {"Heat Transfer", "Current Setting", "Program start "};
// second menu line - mode select
char sequenceModes[3][20] = {"OFF Temp >","< Maintain >", "< SYSTEM OFF "};
// second menu line - options settings
char sequenceOptions[3][17] = {"OFF TEMP: ", "Maintain: ", "on/off "};
// lcd header house temp
void lcdHeader()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("HOUSE");
lcd.setCursor(11,0);
lcd.print("ROOF");
sensors.requestTemperatures();
float house = (sensorValue(insideThermometer));
float roof = (sensorValue(outsideThermometer));
lcd.setCursor (0,1);
lcd.print (house);
lcd.setCursor (11,1);
lcd.print (roof);
}
void setup()
{
//Ardunio Pin MODES
pinMode(pinTemp1, OUTPUT);
pinMode(pinTemp2, OUTPUT);
//LCD Size
lcd.begin(16, 2);
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
// locate devices on the bus
Serial.print("Locating devices...");
Serial.print("Found ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" devices.");
// report parasite power requirements
Serial.print("Parasite power is: ");
if (sensors.isParasitePowerMode()) Serial.println("ON");
else Serial.println("OFF");
// set the resolution to 9 bit
sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);
sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
}
// ===================================================================
// main loop with new key detection
int keyEvent = -1;
int lastEvent = -1;
int countEvent = 0;
//Key message
char msgs[5][3] = {
"> ",
"^ ",
"v ",
"< ",
"* " };
void updateScreen()
{
lcd.clear();
lcd.print(sequenceHeader[programmSequence]);
lcd.setCursor(0,1);
switch(programmSequence)
{
case sequenceModeSelect:
menuModeSelect(keyEvent);
break;
case sequenceModeOption:
menuOptionSelect(keyEvent);
break;
case sequenceModeProgram:
break;
}
}
//functions that reads temp from sensors and returns as floating point value.
float sensorValue (byte deviceAddress[])
{
float tempC = sensors.getTempC (deviceAddress);
float temp = (DallasTemperature::toFahrenheit(tempC));
return tempC;
}
but the lcdHeader();
how do i make this function loop only when no keys on lcd keypad sheild have not been pressed unsure how to write it with millis() to compare the keybutton press time for say 5 seconds and if no buttons pressed in the time run the lcdheader() as that will be enough time
Create 2 global variables:
unsigned long lastKeyPress = 0;
unsigned long interval = 5000; // 5 seconds
Then, in the function that detects a key press, add:
lastKeyPress = millis();
after detecting that a key has been pressed.
Then, instead of
lcdHeader();
(which is a lousy name for a function, as it contains no verbs that indicate the action that is to be performed), use: