void menuChanged(MenuChangeEvent changed){
MenuItem newMenuItem=changed.to; //get the destination menu
lcd.setCursor(0,1); //set the start position for lcd printing to the second row
if(newMenuItem.getName()==menu.getRoot()){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Settings");
}else if(newMenuItem.getName()=="Brightness"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Brightness");
}else if(newMenuItem.getName()=="Calibration"){
lcd.print("Calibration");
}else if(newMenuItem.getName()=="Sensor 1"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Sensor 1 ");
}else if(newMenuItem.getName()=="Temperature"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Temperature ");
}else if(newMenuItem.getName()=="Humidity"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Humidity");
}else if(newMenuItem.getName()=="Sensor 2 Temp"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Sensor 2 Temp");
}else if(newMenuItem.getName()=="Dew Enable"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Dew Enable");
}else if(newMenuItem.getName()=="Alarms"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Alarms ");
}else if(newMenuItem.getName()=="Low Alarm"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Low Alarm");
}else if(newMenuItem.getName()=="High Alarm"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("High Alarm");
}
}
void menuUsed(MenuUseEvent used){
lcd.setCursor(0,0);
lcd.print("You used");
lcd.setCursor(0,1);
lcd.print(used.item.getName());
delay(3000); //delay to allow message reading
lcd.setCursor(0,0);
menu.toRoot(); //back to Main
}
void readButtons(){ //read buttons status
int reading;
int ButtonEnterState=LOW; // the current reading from the Enter input pin
int ButtonEscState=LOW; // the current reading from the input pin
int ButtonLeftState=LOW; // the current reading from the input pin
int ButtonRightState=LOW; // the current reading from the input pin
//Enter button
// read the state of the switch into a local variable:
reading = analogRead(0);
// check to see if you just pressed the enter button
// (i.e. the input is at 10 and 18):
if (reading > 10 && reading < 18) {
ButtonEnterState = HIGH;
ButtonEscState=LOW;
ButtonLeftState=LOW;
ButtonRightState=LOW; }
//Esc button
// check to see if you just pressed the Down button
// (i.e. the input is 65 and 75):
else if (reading > 65 && reading < 75) {
ButtonEscState = HIGH;
ButtonEnterState=LOW;
ButtonLeftState=LOW;
ButtonRightState=LOW;}
//Right button
// check to see if you just pressed the Down button
// (i.e. the input is 115 and 128)
else if (reading > 115 && reading < 128) {
ButtonRightState = HIGH;
ButtonEnterState=LOW;
ButtonEscState=LOW;
ButtonLeftState=LOW;}
//Left button
// check to see if you just pressed the Down button
// (i.e. the input is 160and 175
else if (reading > 160 && reading < 175) {
ButtonLeftState = HIGH;
ButtonEnterState=LOW;
ButtonEscState=LOW;
ButtonRightState=LOW;}
//records which button has been pressed
if (ButtonEnterState==HIGH){
ButtonPushed=buttonEnter;
}else if(ButtonEscState==HIGH){
ButtonPushed=buttonEsc;
}else if(ButtonRightState==HIGH){
ButtonPushed=buttonRight;
}else if(ButtonLeftState==HIGH){
ButtonPushed=buttonLeft;
}else{
ButtonPushed=0;
}
}