The run down. i am making a system to automate the manual hvac system in my car using servo motors, lcd screen, yet to be determined amount of buttons for random features, and a bunch of replacement knobs that are gears to engage with a set of gears mounted to the servos.
my problem is really with the menu system i am trying to build.
i am using MenuBackend in my sketch.
heres das sketch so far. it is work in progress obviously. this does not compile
#include <MenuBackend.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
/*
root
Climate Control
auto Set Temp
man Temp Up
Down
Mode Off
Max AC
Norm AC
Vent
Defrost
Floor
Mix
*/
byte upArrow[8] = {
B00000,
B00000,
B00100,
B01010,
B10001,
B00000,}
;
MenuBackend menu = MenuBackend(menuUseEvent, menuChangeEvent);
MenuItem miCC = MenuItem("CC");
MenuItem miAuto = MenuItem("Auto");
MenuItem miSetTemp = MenuItem("Set Temp");
MenuItem miSemiAuto = MenuItem("Semi Auto");
MenuItem miMan = MenuItem("Manual");
MenuItem miTemp = MenuItem("Temp");
MenuItem miManUp = MenuItem("Up");
MenuItem miManDwn = MenuItem("Down");
MenuItem miMode = MenuItem("Mode");
MenuItem miOff = MenuItem("Off");
MenuItem miMaxAC = MenuItem("Max");
MenuItem miNormAC = MenuItem("NormAC");
MenuItem miFloor = MenuItem("Floor");
MenuItem miDefrost = MenuItem("Defrost");
MenuItem miMix = MenuItem("Mix");
MenuItem miVent = MenuItem("Vent");
void menuUseEvent(MenuUseEvent used)
{
if (used.item == miCC) {
lcd.clear();
lcd.print("Climate");
lcd.setCursor(0,1);
lcd.print("Control");
lcd.setCursor(11,0);
lcd.write(byte(0));
lcd.print("Auto");
lcd.setCursor(10,1);
lcd.print("Manual");
}
}
void menuChangeEvent(MenuChangeEvent changed)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" ");
lcd.print(changed.to.getName());
delay(500);
Serial.print("Menu change ");
Serial.print(changed.from.getName());
Serial.print(" ");
Serial.println(changed.to.getName());
}
void menuSetup()
{
menu.getRoot().add(miCC);
miCC.add(miAuto);
miAuto.add(miMan);
miMan.add(miSemiAuto);
miAuto.addRight(miSetTemp);
miMan.addRight(miTemp);
miTemp.addRight(miMode);
miTemp.add(miManUp);
miManUp.add(miManDwn);
miMode.add(miOff);
miOff.add(miVent);
miVent.add(miNormAC);
miNormAC.add(miMaxAC);
miMaxAC.add(miFloor);
miFloor.add(miMix);
miMix.addRight(miDefrost);
}
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
int read_LCD_buttons()
{
adc_key_in = analogRead(0);
if (adc_key_in > 1000) return btnNONE;
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
return btnNONE; // when all others fail, return this...
}
long timeSincePush = 0;
long timeNoPush = 0;
int rightBtn;
void getButton ()
{
int currentMenu;
lcd_key = read_LCD_buttons(); // read the buttons=
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
if (currentMenu.item == miMan) {
lcd.clear();
lcd.print("i win");}
timeSincePush = millis();
break;
}
case btnLEFT:
{
timeSincePush = millis();
break;
}
case btnUP:
{
timeSincePush = millis();
break;
}
case btnDOWN:
{
timeSincePush = millis();
break;
}
case btnSELECT:
{
timeSincePush = millis();
break;
}
case btnNONE:
{
timeNoPush = millis();
break;
}
}
}
void setup()
{
lcd.createChar(0, upArrow);
Serial.begin(9600);
menuSetup();
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print(" Welcome Justin"); // print a simple message
delay(2500);
lcd.setCursor(0,0);
lcd.print("Climate Control");
lcd.setCursor(11,1);
lcd.print("V1.00");
delay(5000);
}
void loop()
{
getButton();
}
so what i am wanting to do is call that "used" from menuUseEvent function so i can fudge the output of my buttons to do something other then travel menu. ie when in temp menu i want up and down to change temp up and down. in my posted code you can see one of my failed attempts to change the output of rightBtn to display some victory text of my/our beating this small coding battle
finally my question is..... how should i be calling this function out in my getButton function. i believe i am wanting to use either "item" or "to" to be able to manipulate the menus how i would like to.
there are also functions like getCurrent and getRoot i would like to be able to call.