can't enter in ITEM_COMMAND #120
Replies: 1 comment
-
Could you please better format the code. It's not easy to understand it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi dear,
I'm actually using your LcdMenu.h library but I have problem to enter in the ITEM_COMMAND.
I am beginner in programming, could you help me?
When I enter to the ITEM_COMMAND to call the function "remplissage40g()" nothing happen
Thank you for your help :)
`/*
Basic Menu
https://lcdmenu.forntoh.dev/examples/basic
*/
#include <LiquidCrystal_I2C.h>
#include <LcdMenu.h>
#include <ItemSubMenu.h>
#include <ItemCommand.h>
#include "AiEsp32RotaryEncoder.h"
#include "Arduino.h"
#include "HX711.h"
#define DEBUG_HX711
// calibration parameter from calibrating code with known values
#define CALIBRATION_FACTOR 210
#define RPWM 19 // RPWM BTS7960
#define LPWM 18 // LPWM BTS7960
#define PWM 23// pin R_EN and L_EN BTS7960
#define LCD_ROWS 4
#define LCD_COLS 20
int a=0;
// data pin and clock pin HX711
byte pinData = 16;
byte pinClk = 4;
// define HX711
HX711 scale;
//Configure keyboard keys (ASCII)
#define UP 56 // NUMPAD 8
#define DOWN 50 // NUMPAD 2
#define LEFT 52 // NUMPAD 4
#define RIGHT 54 // NUMPAD 6
#define ENTER 53 // NUMPAD 5
#define BACK 55 // NUMPAD 7
#define BACKSPACE 8 // BACKSPACE
#define CLEAR 46 // NUMPAD .
extern MenuItem* menuprincipalMenu[];
extern MenuItem* remplissageMenu[];
extern MenuItem* manuelMenu[];
extern MenuItem* reglagesMenu[];
extern MenuItem* doseaMenu[];
extern MenuItem* dosebMenu[];
extern MenuItem* dosecMenu[];
extern MenuItem* dosedMenu[];
extern MenuItem* doseeMenu[];
#define ROTARY_ENCODER_A_PIN 33 //DT
#define ROTARY_ENCODER_B_PIN 32 //CLK
#define ROTARY_ENCODER_BUTTON_PIN 27
#define ROTARY_ENCODER_VCC_PIN -1
#define ROTARY_ENCODER_STEPS 4
AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(
ROTARY_ENCODER_A_PIN,
ROTARY_ENCODER_B_PIN,
ROTARY_ENCODER_BUTTON_PIN,
ROTARY_ENCODER_VCC_PIN
);
/LCD/
// Create the lcd object address 0x3F and 16 columns x 2 rows
LiquidCrystal_I2C lcd (0x27, LCD_ROWS,LCD_COLS);
void motor_CW() {
digitalWrite (LPWM, LOW);
digitalWrite (RPWM, HIGH);
analogWrite (PWM,500);
Serial.println ("CW");
}
void motor_CCW() {
digitalWrite (LPWM, HIGH);
digitalWrite (RPWM, LOW);
analogWrite (PWM,500);
Serial.println ("CCW");
}
void motor_stop() {
digitalWrite (LPWM, LOW);
digitalWrite (RPWM, LOW);
analogWrite (PWM,0);
Serial.println ("STOP");
}
void remplissage40g() {
Serial.println ("test");
while(scale.get_units()<40)
{
motor_CW();
}
motor_stop();
}
MAIN_MENU(
//Page d'accueil
ITEM_SUBMENU("Abeilles&Papillons", menuprincipalMenu)
);
//Menu principal
SUB_MENU(menuprincipalMenu, mainMenu,
ITEM_SUBMENU("Remplissage", remplissageMenu),
ITEM_SUBMENU("Manuel", manuelMenu),
ITEM_SUBMENU("Reglages", reglagesMenu)
);
LcdMenu menu(LCD_ROWS, LCD_COLS);
void rotary_onButtonClick()
{
static unsigned long lastTimePressed = 0; // Soft debouncing
if (millis() - lastTimePressed < 500)
{
return;
}
lastTimePressed = millis();
Serial.print("button pressed ");
Serial.print(millis());
Serial.println(" milliseconds after restart");
}
void rotary_loop() {
//first lets handle rotary encoder button click
if (rotaryEncoder.currentButtonState() == BUT_RELEASED) {
//we can process it here or call separate function like:
rotary_onButtonClick();
}
if (rotaryEncoder.isEncoderButtonClicked())
{
Serial.print("Clicked");
menu.enter();
}
//lets see if anything changed
int8_t encoderDelta = rotaryEncoder.encoderChanged();
if (rotaryEncoder.currentButtonState() == BUT_PUSHED){Serial.print("Clicked"); menu.enter();}
}
void setup() {
rotaryEncoder.begin();
rotaryEncoder.setup([]{rotaryEncoder.readEncoder_ISR();});
Serial.begin(9600);
// Initialize LcdMenu with the menu items
menu.setupLcdWithMenu(0x27, mainMenu);
//Initializing sensor
scale.begin(pinData, pinClk);
// apply the calibration value
scale.set_scale(CALIBRATION_FACTOR);
// Initialize the tare
//Assuming there is no weight on the scale at start up, reset the scale to 0
scale.tare();
pinMode (RPWM, OUTPUT);
pinMode (PWM, OUTPUT);
pinMode (LPWM, OUTPUT);
}
void loop() {
rotary_loop();
if (!Serial.available()) return;
char command = Serial.read();
if (command == UP)
menu.up();
else if (command == DOWN)
menu.down();
else if (command == LEFT)
menu.left();
else if (command == RIGHT)
menu.right();
else if (command == ENTER)
menu.enter();
else if (command == BACK)
menu.back();
}`
Beta Was this translation helpful? Give feedback.
All reactions