Hello everyone, pretty knew to arduino and I am currently trying to create a menu system on an lcd thats controlled by a button and a joystick(including the button on it)
what i wanted it to do is the button switches from lcd off to lcd on with “testing mode on”
and then with the joystick i want to be able to scroll through the different testing menus and click it in and show a message of testing now or something. i cant really get any of it working if anyone has any suggestions on what to do next let me know thank you.
#include <LiquidCrystal.h> // command used to include a specific library that helps me communicate clearly with the lcd screen
//lcd screen setup
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int xp=0;
//button setup
int buttonPin = 4;
boolean on=false;
int buzzer = 5;
int Rled = 22; // red portion of RGB led
int Gled = 24; // green portion of RGB led
int Bled = 26; // blue portion of RGB led
//joystick setup
const int SW_pin = 13; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output
boolean updown=false;
long lastDebounceTime = 0;
long debounceDelay = 70;
int SwitchState;
int lastSwitchState = LOW;
int Mode = 0;
int oldMode = 0;
int ButtonState;
int lastButtonState = LOW;
int ButtonMode = 0;
int oldButtonMode = 0;
int UpState;
int lastUpState = LOW;
int UpMode = 0;
int oldUpMode = 0;
void setup() {
pinMode(buzzer, OUTPUT);
pinMode(Rled, OUTPUT);
pinMode(Gled, OUTPUT);
pinMode(Bled, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(115200);
//lcd screen
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop() {
Buttons();
Serial.print(digitalRead(SW_pin));
Serial.print("\n");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pin));
Serial.print("\n\n");
switch(ButtonMode){
case 1:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Testing Mode");
lcd.setCursor(0,1);
lcd.print("ON");
oldButtonMode = ButtonMode;
break;
switch(UpMode){
case 1:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("IMU Test");
switch(Mode){
case 1:
lcd.setCursor(0,1);
lcd.print("Testing");
delay(5000);
break;
default:
lcd.setCursor(0,1);
lcd.print("Press to Start");
break;
}
default:
break;
}
default:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("LCD");
lcd.setCursor(0,1);
lcd.print("OFF");
oldButtonMode = 0;
break;
}
}
void Buttons(){
int ButtonReading = digitalRead(buttonPin);
if (ButtonReading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (ButtonReading != ButtonState) {
ButtonState = ButtonReading;
if (ButtonState == HIGH) {
ButtonMode = oldButtonMode + 1;
}
}
}
lastButtonState = ButtonReading;
int ModeReading = digitalRead(SW_pin);
if (ModeReading != lastSwitchState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (ModeReading != SwitchState) {
SwitchState = ModeReading;
if (SwitchState == HIGH) {
Mode = oldMode + 1;
}
}
}
lastSwitchState = ModeReading;
int UpReading = analogRead(X_pin);
if (UpReading != lastUpState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (UpReading != UpState) {
UpState = UpReading;
if (UpState < 450) {
UpMode = oldUpMode + 1;
}
}
}
lastUpState = UpReading;
}
if it helps this is kind of what I’m looking for but with the function of the joystick button interacting with the menu and not the y axis. plus i need to add the turn off button