#include <LiquidCrystal.h>
// LCD module connections (modify as per your wiring)
LiquidCrystal lcd(A4, A5, A0, A1, A2, A3);
// Define button pins
const int button1 = 4; // Button 1 connected to digital pin 4
const int button2 = 7; // Button 2 connected to digital pin 7
const int button3 = 0; // Button 3 connected to digital pin 0 (RX pin)
const int button4 = 6; // Button 4 connected to digital pin 6
const int button5 = 5; // Button 5 connected to digital pin 5
const int button6 = 2; // Button 6 connected to digital pin 2
const int button7 = 1; // Button 7 connected to digital pin 1 (TX pin)
const int button8 = 3; // Button 8 connected to digital pin 3
// Menu state variables
int currentSetting = 0; // Variable to track current setting index
// Settings variables
int motor1Speed = 0; // Initial speed of motor 1
int motor2Speed = 0; // Initial speed of motor 2
int motor1Degree = 0; // Initial degree setting for motor 1
int motor2Degrees[3] = {0, 0, 0}; // Initial degrees settings for motor 2 (M1, M2, M3)
int currentMotor2DegreeIndex = 0; // Index for current motor 2 degree setting
int motor1Direction = 0; // Initial direction setting for motor 1
int cyclelimit = 0; // Initial cycle number
void setup() {
// Initialize LCD
lcd.begin(16, 2);
// Initialize buttons as inputs with pull-ups
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(button4, INPUT_PULLUP);
pinMode(button5, INPUT_PULLUP);
pinMode(button6, INPUT_PULLUP);
pinMode(button7, INPUT_PULLUP);
pinMode(button8, INPUT_PULLUP);
// Display initial home screen
displayHomeScreen();
}
void loop() {
// Check for button presses and handle accordingly
if (digitalRead(button1) == LOW) {
// Button 1 pressed: Enter Settings Menu
delay(250); // Debounce delay
enterSettingsMenu();
} else if (digitalRead(button2) == LOW) {
// Button 2 pressed: Move to next setting
delay(250); // Debounce delay
moveToNextSetting();
} else if (digitalRead(button3) == LOW) {
// Button 3 pressed: Increase value of current setting
delay(250); // Debounce delay
increaseCurrentValue();
} else if (digitalRead(button4) == LOW) {
// Button 4 pressed: Decrease value of current setting
delay(250); // Debounce delay
decreaseCurrentValue();
} else if (digitalRead(button5) == LOW) {
// Button 5 pressed: Save settings and return to Home Screen
delay(250); // Debounce delay
saveSettings();
}
// Other functionality and tasks can be added here
}
void displayHomeScreen() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Home Screen");
}
void enterSettingsMenu() {
lcd.clear();
lcd.setCursor(0, 0);
switch (currentSetting) {
case 0:
lcd.print("MOTOR 1 SPEED:");
lcd.setCursor(0, 1);
lcd.print(motor1Speed);
break;
case 1:
lcd.print("MOTOR 2 SPEED:");
lcd.setCursor(0, 1);
lcd.print(motor2Speed);
break;
case 2:
lcd.print("MOTOR 1 DEGREE:");
lcd.setCursor(0, 1);
lcd.print(motor1Degree);
break;
case 3:
lcd.print("MOTOR 2 DEG M1:");
lcd.setCursor(0, 1);
lcd.print(motor2Degrees[0]);
break;
case 4:
lcd.print("MOTOR 2 DEG M2:");
lcd.setCursor(0, 1);
lcd.print(motor2Degrees[1]);
break;
case 5:
lcd.print("MOTOR 2 DEG M3:");
lcd.setCursor(0, 1);
lcd.print(motor2Degrees[2]);
break;
case 6:
lcd.print("MOTOR 1 DIR:");
lcd.setCursor(0, 1);
lcd.print(motor1Direction == 0 ? "CW" : "CCW");
break;
case 7:
lcd.print("CYCLE LIMIT:");
lcd.setCursor(0, 1);
lcd.print(cyclelimit);
break;
default:
break;
}
}
void moveToNextSetting() {
currentSetting++;
if (currentSetting >= 8) { // Adjust this based on number of settings
currentSetting = 0; // Wrap around to the first setting
}
displayCurrentSetting();
}
void increaseCurrentValue() {
// Implement logic to increase value based on current setting
switch (currentSetting) {
case 0:
motor1Speed += 10;
break;
case 1:
motor2Speed += 10;
break;
case 2:
motor1Degree += 90;
break;
case 3:
motor2Degrees[0] += 45;
break;
case 4:
motor2Degrees[1] += 45;
break;
case 5:
motor2Degrees[2] += 45;
break;
case 6:
motor1Direction = !motor1Direction; // Toggle direction
break;
case 7:
cyclelimit++;
break;
default:
break;
}
displayCurrentSetting();
}
void decreaseCurrentValue() {
// Implement logic to decrease value based on current setting
switch (currentSetting) {
case 0:
motor1Speed -= 10;
break;
case 1:
motor2Speed -= 10;
break;
case 2:
motor1Degree -= 90;
break;
case 3:
motor2Degrees[0] -= 45;
break;
case 4:
motor2Degrees[1] -= 45;
break;
case 5:
motor2Degrees[2] -= 45;
break;
case 6:
motor1Direction = !motor1Direction; // Toggle direction
break;
case 7:
cyclelimit--;
break;
default:
break;
}
displayCurrentSetting();
}
void saveSettings() {
// Implement saving settings logic here (e.g., save to EEPROM)
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Settings Saved");
delay(1000); // Display message for 1 second
displayHomeScreen();
}
void displayCurrentSetting() {
lcd.clear();
lcd.setCursor(0, 0);
switch (currentSetting) {
case 0:
lcd.print("MOTOR 1 SPEED:");
lcd.setCursor(0, 1);
lcd.print(motor1Speed);
break;
case 1:
lcd.print("MOTOR 2 SPEED:");
lcd.setCursor(0, 1);
lcd.print(motor2Speed);
break;
case 2:
lcd.print("MOTOR 1 DEGREE:");
lcd.setCursor(0, 1);
lcd.print(motor1Degree);
break;
case 3:
lcd.print("MOTOR 2 DEG M1:");
lcd.setCursor(0, 1);
lcd.print(motor2Degrees[0]);
break;
case 4:
lcd.print("MOTOR 2 DEG M2:");
lcd.setCursor(0, 1);
lcd.print(motor2Degrees[1]);
break;
case 5:
lcd.print("MOTOR 2 DEG M3:");
lcd.setCursor(0, 1);
lcd.print(motor2Degrees[2]);
break;
case 6:
lcd.print("MOTOR 1 DIR:");
lcd.setCursor(0, 1);
lcd.print(motor1Direction == 0 ? "CW" : "CCW");
break;
case 7:
lcd.print("CYCLE LIMIT:");
lcd.setCursor(0, 1);
lcd.print(cyclelimit);
break;
default:
break;
}
}