Sub_Menu, Scrolling Issues #95
-
Hello everyone, The Code below gets compiled and it partially does what I need it to do. But there are a few bugs that I can't seem to figure out. The Main Menu works to a certain extend. I can focus the lines and when focusing on a line that is not on the screen, the menu scrolls to that line. I think I can live with that, it would just be nice to have a focus that works up and downwards. As I now can't shift the screens anymore (because there is only 1 screen), I can only focus downwards and once the bottom is reached it jumps back to the first line. The "Water Menu" works to certain extend as well. When opening the menu it shows the bottom two lines instead of the first two lines. Scrolling works and the back function also works. What I have to fix is the adjustment of the values (have not started working on that yet). But here comes the first problem, when I select "Back", I jump to the Main Menu (great!), however, from there I can not change the focus anymore, I will always end up in the "Water Menu" again (all buttons bring me back to the "Water Menu"). Only rebooting the Arduino will fix this issue. The "Formula Menu" has the same issue as the "Water Menu". The "Machine Menu" has a different problem. I believe I know partially where it is coming from but don't know how to fix it. The LiquidMenu Library works up to 4 items but seems to have an issue with anything above 4. There are workarounds that I have not managed to get working. What I see in the "Machine Menu" is only a screen that shows "Test 3.5.0" in line 1 and "Back" in line 2. When I focus the lines, I focus 4 times on the "Test 3.5.0" item and once on the "Back" item. When selecting back I jump back to the main menu and have the same problem as the other menus. ` #include "Button.h"
#include <LiquidCrystal.h> // include the LiquidCrystal library
#include <LiquidMenu.h>
// initialize the library with the LCD pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// define the button pins
const bool pullup = true;
Button Down_Button(6, pullup);
Button Up_Button(7, pullup);
Button Select_Button(8, pullup);
Button Back_Button(9,pullup);
Button Spare_Button(10,pullup);
/*
* An enumerator can be used for the callback functions. It sets the number
* for similar functions. Later when a function is attached it can be passed
* with this enum rather than a magic number.
*/
enum FunctionTypes {
increase = 1,
decrease = 2,
};
//Dispensing Formulas
// Water Variables Definition
int water_amount = 0;
int water_temperature = 0;
int water_speed = 0;
//Formula Variables Definition
int formula_amount = 0;
//Test Values
int formula_test_1 = 0;
int formula_test_2 = 0;
int value_test_1 = 0;
int value_test_2 = 0;
int value_test_3 = 0;
int value_test_4 = 0;
int value_test_5 = 0;
//Menu Setup
uint16_t var = 123;
//Main Menu
LiquidLine main_line_1(0, 0, "Water Set.");
LiquidLine main_line_2(0, 0, "Formula Set.");
LiquidLine main_line_3(0, 0, "Machine Set.");
LiquidScreen smain_1(main_line_1,main_line_2,main_line_3);
LiquidMenu mmain(lcd, smain_1, 1);
//Water Menu
LiquidLine water_line_1(0, 0, "Water Amount", water_amount);
LiquidLine water_line_2(0, 0, "Water Temperature", water_temperature);
LiquidLine water_line_3(0, 0, "Flow Speed", water_speed);
LiquidLine mmback_line(0, 0, "Back");
LiquidScreen swater_1(water_line_1, water_line_2, water_line_3, mmback_line);
LiquidMenu mwater(lcd, swater_1);
//Formula Menu
LiquidLine formula_line_1(0, 0, "Formula Amount", formula_amount);
LiquidLine formula_line_2(0, 0, "Formula Test.1", formula_test_1);
LiquidLine formula_line_3(0, 0, "Formula Test.2", formula_test_2);
LiquidScreen sformula_1(formula_line_1, formula_line_2, formula_line_3, mmback_line);
LiquidMenu mformula(lcd, sformula_1);
//Machine Menu
LiquidLine machine_line_1(0, 0, "Test 3.1.", value_test_1);
LiquidLine machine_line_2(0, 0, "Test 3.2.", value_test_2);
LiquidLine machine_line_3(0, 0, "Test 3.3.", value_test_3);
LiquidLine machine_line_4(0, 0, "Test 3.4.", value_test_4);
LiquidLine machine_line_5(0, 0, "Test 3.5.", value_test_5);
LiquidScreen smachine_1(machine_line_1, machine_line_2);
LiquidMenu mmachine(lcd, smachine_1);
//Overall Menu
LiquidSystem overall_menu(mmain, mwater, mformula, mmachine);
void buttonsCheck() {
if (Down_Button.check() == LOW) {
overall_menu.next_screen();
}
if (Up_Button.check() == LOW) {
overall_menu.previous_screen();
}
if (Select_Button.check() == LOW) {
overall_menu.call_function(increase);
}
if (Back_Button.check() == LOW) {
overall_menu.call_function(decrease);
}
if (Spare_Button.check() == LOW) {
overall_menu.switch_focus();
}
}
// Used for attaching something to the lines, to make them focusable.
void fBlankFunction() {
return;
}
void goto_mwater() {
overall_menu.change_menu(mwater);
}
void goto_mformula() {
overall_menu.change_menu(mformula);
}
void goto_mmachine() {
overall_menu.change_menu(mmachine);
}
//Callback function that will be attached to back_line to Main Menu
void mm_go_back(){
overall_menu.change_menu(mmain);
}
void setup() {
lcd.begin(16, 2);
// print something on the first row
lcd.setCursor(3, 0); // set the cursor position
lcd.print("Welcome to");
// print something on the second row
lcd.setCursor(2, 1); // set the cursor position
lcd.print("XXYYZZ");
delay(3000);
lcd.clear();
//Attaching a function to the lines is required for scrolling to work
//Main
main_line_1.attach_function(1, goto_mwater);
main_line_2.attach_function(1, goto_mformula);
main_line_3.attach_function(1, goto_mmachine);
mmback_line.attach_function(1, mm_go_back);
//Water
water_line_1.attach_function(1, fBlankFunction);
water_line_2.attach_function(1, fBlankFunction);
water_line_3.attach_function(1, fBlankFunction);
//Formula
formula_line_1.attach_function(1, fBlankFunction);
formula_line_2.attach_function(1, fBlankFunction);
formula_line_3.attach_function(1, fBlankFunction);
//Machine
machine_line_1.attach_function(1, fBlankFunction);
machine_line_2.attach_function(1, fBlankFunction);
machine_line_3.attach_function(1, fBlankFunction);
machine_line_4.attach_function(1, fBlankFunction);
machine_line_5.attach_function(1, fBlankFunction);
// Set the number of lines the display has
//Main
smain_1.set_displayLineCount(2);
//Water
swater_1.set_displayLineCount(2);
//Formula
sformula_1.set_displayLineCount(2);
//Machine
smachine_1.set_displayLineCount(2);
smachine_1.add_line(machine_line_3);
smachine_1.add_line(machine_line_4);
smachine_1.add_line(machine_line_5);
smachine_1.add_line(mmback_line);
mmain.add_screen(smain_1);
mwater.add_screen(swater_1);
mformula.add_screen(sformula_1);
mmachine.add_screen(smachine_1);
mmain.update();
mwater.update();
mformula.update();
mmachine.update();
overall_menu.update();
}
void loop() {
buttonsCheck();
}
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I was able to fix some of my problems. One of the issues was that I was missing to avoid flickering I introduced a bool that checks if the buttons were pressed and only executes the menu.update if true |
Beta Was this translation helpful? Give feedback.
-
I found the solution to the problem of not being able to scroll more than 4 line items. the |
Beta Was this translation helpful? Give feedback.
-
The missing solution is I can "focus" upwards |
Beta Was this translation helpful? Give feedback.
This was actually explained in the manual and totally missed it. The solution is to change the
Menu.switch_focus(true) //Focus down
to
Menu.switch_focus(false) //Focus up