Hey all,
First off i apologize if this is in the wrong area, wasnt sure if this goes under Programming Questions or Project Guidance.
I'm having difficulty trying to set up a menu with my arduino and lcd screen.
what im trying to do, is have a display page that shows live data all the time, if enter button is held for 5 secs or more enter menu where you can change some values for a warning led or select which set of live data to display (i.e. live 1 = 1,2,3,4 sensor/ live 2 = 5,6,7,8 Sensor).
I imagine a structure like so: you always showing live data, it shows real time temp, etc..
Live Data
|
Data Selection - Option A
| - Option B
|
Warning System - Option A - Lower
| - Raise
Option B - Lower
| - Raise
Option C - Lower
- Raise
if not sure how to do this exactly, i know i need Menubackend which i have, i haven't found many tutorials on it or examples, and of what examples i could find, i could never get it working, it would either not work in the menu or it would work in the menu but show a static show of the data, not showing live data. So im a little bit confused. I'd Ideally like to be able to do this with 3 buttons, left right and enter, however enter has multiple functions, press long out of menu enters the menu, press short out of menu does nothing, press short in menu selects item, press long in menu goes to previous.
It would be nice if someone could help point me in the right direction, im kind of not sure where to begin
Here is the code i have at the moment :
// include the library code
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 6 on the Arduino
#define ONE_WIRE_BUS 6
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the addresses of your 1-Wire temp sensors.
DeviceAddress TempA = { 0x28, 0xAA, 0x80, 0x2C, 0x04, 0x00, 0x00, 0xBA };
DeviceAddress TempB = { 0x28, 0xE9, 0x80, 0x2C, 0x04, 0x00, 0x00, 0x96 };
DeviceAddress TempC = { 0x28, 0x67, 0xA3, 0x2C, 0x04, 0x00, 0x00, 0xD9 };
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
#define LCD_WIDTH 16
#define LCD_HEIGHT 2
// Assigning Pun Allocations and Names : (analog = A0,A1..) (digital = 0,1,2,3..)
const int FactoryOFF = 13;
//const int WarningLED = 5; //off for testing pins d2,d3,d4,d5 for button array testing
const int analogInput = A0;
//*** Changing and Stored values
//*** Volt Monitor
float VOut = 0.0;
float VIn = 0.0;
float R1 = 2000.0; // *** resistance of R1 ***
float R2 = 1000.0; // *** resistance of R2 ***
int value = 0;
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000; // interval at which to blink (milliseconds)
//*** the setup routine runs once when you press reset:
void setup()
{
//*** set the resolution to 10 bit (good enough?)
sensors.begin();
sensors.setResolution(TempA, 10);
sensors.setResolution(TempB, 10);
sensors.setResolution(TempC, 10);
//*** set up the LCD's number of rows and columns:
lcd.begin(LCD_WIDTH, LCD_HEIGHT,1);
lcd.clear(); // Start with a blank screen
lcd.setCursor(0,0); // Set cursor to column 0, row 0
lcd.print(" Initializing "); // Print 'Initalizing' to the LCD.
delay(500); // Wait 5 seconds, Lcd Flash Sequence
lcd.noDisplay();
delay(500);
lcd.display();
delay(500);
pinMode(FactoryOFF, OUTPUT); // Initialize the factory led as a digital output.
digitalWrite (FactoryOFF, LOW); // Keep it off
pinMode(analogInput, INPUT); // Initialize A0 as Input (Voltage Monitor)
lcd.noDisplay();
delay(500);
lcd.display();
delay(500); // .5 Second Delay before lcd clear
lcd.clear(); // Clear screen after setup run
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
lcd.print("Er");
} else {
lcd.print(tempC,0); // (tempc,x) x = is you variable point, i.e ,0 is no decimal, ,1 is 1 decimal,etc,
}
}
void Voltage()
{
value = analogRead(analogInput);
unsigned long currentMillis = millis();
VOut = (value * 4.81) / 1024.0;
VIn = VOut / (R2/(R1+R2));
VIn = VIn,2; // *** ,x statement modifies the decimal place
lcd.print(VIn);
}
// the loop routine runs over and over again forever:
void loop(void)
{
//*** This would be Data Selection Option A ***
delay(250); // .250 second delay to slow things down
//LCD Menu Item, Set Locations And What Readings.
sensors.requestTemperatures(); // just before this menu runs, read temps
lcd.setCursor(0,0);
lcd.print("TempA"); // Temp A
lcd.setCursor(6,0);
printTemperature(TempA); // Temp A
lcd.setCursor(0,1);
lcd.print("TempB "); // Temp B
lcd.setCursor(6,1);
printTemperature(TempB); // Temp B
lcd.setCursor(9,0);
lcd.print("TempC"); // Temp C
lcd.setCursor(13,0);
printTemperature(TempC); // Temp C
lcd.setCursor(9,1);
lcd.print("V"); // *** Volts ***
lcd.setCursor(11,1);
Voltage(); // *** Volt Input Monitor ***
}