-
Hi, My function should simply print to Serial to : "Function 1". But unfortunately nothing happens. Please help. I paste my code below #include <Arduino.h>
#include "Wire.h"
#include <BfButton.h>
#include <ClickEncoder.h>
#include <TimerOne.h>
#include <LcdMenu.h>
#include <ItemSubMenu.h>
#include <ItemCommand.h>
#include <utils/commandProccesors.h>
#define SW A2
#define DT A1
#define CLK A0
#define LCD_ROWS 2
#define LCD_COLS 16
boolean up = false;
boolean down = false;
boolean button = false;
boolean doubleClicked = false;
ClickEncoder *encoder;
int16_t last, value;
void timerIsr() {
encoder->service();
}
void function1();
extern MenuItem* submenu1[];
MAIN_MENU(
ITEM_BASIC("Menu1"),
ITEM_SUBMENU("Menu2", submenu1)
);
SUB_MENU(submenu1, mainMenu,
ITEM_COMMAND("Submenu 1", function1),
ITEM_BASIC("Submenu 2"),
ITEM_BASIC("Submenu 3")
);
LcdMenu menu(LCD_ROWS, LCD_COLS);
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(SW, INPUT_PULLUP);
pinMode(DT, INPUT_PULLUP);
pinMode(CLK, INPUT_PULLUP);
encoder = new ClickEncoder(DT, CLK, SW);
encoder -> setAccelerationEnabled(false);
Timer1.initialize(1000);
Timer1.attachInterrupt(timerIsr);
Serial.begin(9600);
menu.setupLcdWithMenu(0x27, mainMenu, 20000);
}
void readRotaryEncoder()
{
value += encoder->getValue();
if (value/2 > last) {
last = value/2;
up = true;
delay(150);
}else if (value/2 < last) {
last = value/2;
down = true;
delay(150);
}
}
void readButton() {
ClickEncoder::Button b = encoder->getButton();
if (b != ClickEncoder::Open) {
switch (b) {
case ClickEncoder::Clicked:
button = true;
break;
case ClickEncoder::DoubleClicked:
doubleClicked = true;
}
}
}
// the loop function runs over and over again forever
void loop() {
menu.updateTimer();
readRotaryEncoder();
readButton();
if(button) {
menu.enter();
button = false;
}
if(doubleClicked) {
menu.back();
doubleClicked = false;
}
if(up) {
menu.up();
up = false;
}
if(down) {
menu.down();
down = false;
}
}
void function1() {
Serial.println("Function 1");
} Best Regards |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The problem is likely with your imports |
Beta Was this translation helpful? Give feedback.
The problem is likely with your imports
#include <LcdMenu.h>
must always be the last import after item type imports.See documentation