here the rest of the code.
//Debouncing also- hardware Debounce inplace
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
reading = digitalRead(encoderPushButton);// read the state of the switch into a local variable:
if (reading != lastEncoderButtonState) {// If the switch changed, due to noise or pressing:
lastEnterDebounceTime = millis(); // reset the debouncing timer
}
if ((millis() - lastEnterDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the debounce delay, so take it as the actual current state:
buttonEnterState=reading;
lastEnterDebounceTime=millis();
}
lastEncoderButtonState = reading;// save the reading. Next time through the loop, it'll be the lastButtonState:
//Esc button
reading = digitalRead(buttonPinEsc);// read the state of the switch into a local variable:
if (reading != lastButtonEscState) {// If the switch changed, due to noise or pressing:
lastEscDebounceTime = millis();// reset the debouncing timer
}
if ((millis() - lastEscDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the debounce delay, so take it as the actual current state:
buttonEscState = reading;
lastEscDebounceTime=millis();
}
lastButtonEscState = reading;// save the reading. Next time through the loop, it'll be the lastButtonState:
//Right or Down button
reading = digitalRead(encoderRightRotation);// read the state of the switch into a local variable
if (reading != lastRotationRightState) {//last button state is defaulted int LOW
lastRightDebounceTime = millis();// reset the debouncing timer
}
if ((millis() - lastRightDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the debounce delay, so take it as the actual current state:
buttonRightState = reading;
lastRightDebounceTime =millis();
}
lastRotationRightState = reading; // save the reading. Next time through the loop, it'll be the lastButtonState:
//Left or Up button
reading = digitalRead(encoderLeftRotation);// read the state of the switch into a local variable:
if (reading != lastRotationLeftState) {// If the switch changed, due to noise or pressing:
lastLeftDebounceTime = millis();// reset the debouncing timer
}
if ((millis() - lastLeftDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the debounce delay, so take it as the actual current state:
buttonLeftState = reading;
lastLeftDebounceTime=millis();
}
lastRotationLeftState = reading; // save the reading. Next time through the loop, it'll be the lastButtonState:
//records which button has been pressed
if (buttonEnterState==HIGH){
lastButtonPushed=encoderPushButton;
}
else if(buttonEscState==HIGH){
lastButtonPushed=buttonPinEsc;
}
else if(buttonRightState==HIGH){
lastButtonPushed=encoderRightRotation;
}
else if(buttonLeftState==HIGH){
lastButtonPushed=encoderLeftRotation;
}
else{
lastButtonPushed=0;
}
}
void menuChanged(MenuChangeEvent changed){
MenuItem newMenuItem=changed.to; //get the destination menu
lcd.setCursor(0,0); //set the start position for lcd printing to the second row
if(newMenuItem.getName()==menu.getRoot())
{
lcd.print("Main Menu ");
}
//menu lcd
else if(newMenuItem.getName()=="menuLcd"){
lcd.clear();
lcd.print("Lcd");
}
else if(newMenuItem.getName()=="menuItemOn"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("On");
}
else if(newMenuItem.getName()=="menuItemOff"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Off");
}
//menu set clock
else if(newMenuItem.getName()=="menuSetClock"){
lcd.clear();
lcd.print("Set Clock");
}
else if(newMenuItem.getName()=="menuItemHr"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Hr");
}
else if(newMenuItem.getName()=="menuItemMin"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Min");
}
else if(newMenuItem.getName()=="menuItemSec"){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Sec");
}
else if(newMenuItem.getName()=="menuItemConfirm"){
lcd.clear();
lcd.print("Confirmed");
}
//menu set date
else if(newMenuItem.getName()=="menuSetDate"){
lcd.clear();
lcd.print("Set Date");
}
else if(newMenuItem.getName()=="menuItemDay"){
lcd.clear();
lcd.print("Set Day");
}
else if(newMenuItem.getName()=="menuItemMonth"){
lcd.clear();
lcd.print("Set Month");
}
else if(newMenuItem.getName()=="menuItemYear"){
lcd.clear();
lcd.print("Set Year");
}
//menu set phone number
else if(newMenuItem.getName()=="menuSetPhone"){
lcd.clear();
lcd.print("Set Phone");
}
//menu set pin number
else if(newMenuItem.getName()=="menuSetPin"){
lcd.clear();
lcd.print("Set Pin");
}
//menu set sms
else if(newMenuItem.getName()=="menuSms"){
lcd.clear();
lcd.print("Sms ");
}
else if(newMenuItem.getName()=="menuItemSigStr"){
lcd.clear();
lcd.print("Signal Stre");
}
else if(newMenuItem.getName()=="menuItemBalance"){
lcd.clear();
lcd.print("Balance");
}
else if(newMenuItem.getName()=="menuItemTest"){
lcd.clear();
lcd.print("Test Sms");
}
//menu exit to time
else if(newMenuItem.getName()=="menuExit"){
lcd.clear();
lcd.print("Exit");
}
}
void menuUsed(MenuUseEvent used){ //**if you have a function call it here**
if( used.item == menuItemOn ){
lcd.display();
//digitalWrite(10, HIGH);
//delay(3000);
//digitalWrite(10, LOW);
lcd.clear();
menu.toRoot();
}
if ( used.item == menuItemOff ){
lcd.noDisplay();//your code here
menu.toRoot();
}
//etc.
}
void navigateMenus() {
MenuItem currentMenu=menu.getCurrent();
switch (lastButtonPushed){
case encoderPushButton: // enter pin
if(!(currentMenu.moveDown())){ //if the current menu has a child and enter has been pressed then navigate menu to item below
menu.use();
}
else{ //otherwise, if menu has no child and enter has been pressed---- the current menu is used
menu.moveDown();
}
break;
case buttonPinEsc:
menu.toRoot(); //back to main
break;
case encoderRightRotation:
menu.moveRight();
break;
case encoderLeftRotation:
menu.moveLeft();
break;
}
lastButtonPushed=0; //reset the lastButtonPushed variable
}
I still would like to remove
const int encoderLeftRotation = 44; // pin for the Up button
const int encoderRightRotation = 46; // pin for the Down button
I have tried to remove it but my code fails if I do? even thou they're not wired up? Is the a way rount this?