i am using tact switches but it seems not to do a thing do i need to include buttons.h lib?
#include <MenuBackend.h> //MenuBackend library - copyright by Alexander Brevig
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
const int buttonPinLeft = 6;
const int buttonPinRight = 7;
const int buttonPinEsc = 8;
const int buttonPinEnter = 9;
int lastButtonPushed = 0;
int lastButtonEnterState = HIGH;
int lastButtonEscState = HIGH;
int lastButtonLeftState = HIGH;
int lastButtonRightState = HIGH;
long lastEnterDebounceTime = 0;
long lastEscDebounceTime = 0;
long lastLeftDebounceTime = 0;
long lastRightDebounceTime = 0;
long debounceDelay = 150;
LiquidCrystal_I2C lcd(0X27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup()
{
pinMode(buttonPinLeft, INPUT);
pinMode(buttonPinRight, INPUT);
pinMode(buttonPinEnter, INPUT);
pinMode(buttonPinEsc, INPUT);
digitalWrite(buttonPinLeft, HIGH);
digitalWrite(buttonPinRight, HIGH);
digitalWrite(buttonPinEnter, HIGH);
digitalWrite(buttonPinEsc, HIGH);
void loop()
{
readButtons();
navigateMenus();
} //loop()...
void readButtons(){ //read buttons status
int reading;
int buttonEnterState=HIGH;
int buttonEscState=HIGH;
int buttonLeftState=HIGH;
int buttonRightState=HIGH;
//Enter button
reading = digitalRead(buttonPinEnter)
if (reading != lastButtonEnterState) {
lastEnterDebounceTime = millis();
}
if ((millis() - lastEnterDebounceTime) > debounceDelay) {
:
buttonEnterState=reading;
lastEnterDebounceTime=millis();
}
lastButtonEnterState = reading;
//Esc button
if (reading != lastButtonEscState) {
// reset the debouncing timer
lastEscDebounceTime = millis();
}
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();
}
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonEscState = reading;
//Down button
// read the state of the switch into a local variable:
reading = digitalRead(buttonPinRight);
// check to see if you just pressed the Down button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonRightState) {
// reset the debouncing timer
lastRightDebounceTime = millis();
}
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();
}
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonRightState = reading;
//Up button
// read the state of the switch into a local variable:
reading = digitalRead(buttonPinLeft);
// check to see if you just pressed the Down button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonLeftState) {
// reset the debouncing timer
lastLeftDebounceTime = millis();
}
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();;
}
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonLeftState = reading;
//records which button has been pressed
if (buttonEnterState==LOW){
lastButtonPushed=buttonPinEnter;
}else if(buttonEscState==LOW){
lastButtonPushed=buttonPinEsc;
}else if(buttonRightState==LOW){
lastButtonPushed=buttonPinRight;
}else if(buttonLeftState==LOW){
lastButtonPushed=buttonPinLeft;
}else{
lastButtonPushed=0;
}
}
void navigateMenus() {
MenuItem currentMenu=menu.getCurrent();
switch (lastButtonPushed){
case buttonPinEnter:
if(!(currentMenu.moveDown())){ //if the current menu has a child and has been pressed enter then menu navigate to item below
menu.use();
}else{ //otherwise, if menu has no child and has been pressed enter the current menu is used
menu.moveDown();
}
break;
case buttonPinEsc:
menu.toRoot(); //back to main
break;
case buttonPinRight:
menu.moveRight();
break;
case buttonPinLeft:
menu.moveLeft();
break;
}
lastButtonPushed=0; //reset the lastButtonPushed variable
}