// Libraries
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// LCD Initialization (20x4, I2C address 0x27)
LiquidCrystal_I2C lcd(0x27, 20, 4);
// Button Pins
#define UP 26
#define DOWN 27
#define LEFT 28
#define RIGHT 29
#define ENTER 30
// Parameters
float voltage = 12.8; // Voltage
int holeInterval = 2; // Hole Interval
int plotDistance = 30; // Plot Distance
int movementSpeed = 50; // Movement Speed
int dispenseSpeed = 50; // Dispense Speed
// Menu Options Array
const char *option[] = {"Config", "AR", "Man"};
const int menuSize = sizeof(option) / sizeof(option[0]); // Calculate menu size
int currentParametersOption = 0; // Selected Option (Configuration, Auto Run, Manual Controller)
bool parametersSelected = false; // Enter Button State
void setup() {
// Initialize LCD
lcd.init();
lcd.backlight();
// Display Startup Screen
lcd.setCursor(0, 0); lcd.print(" Seed Sowing Robot ");
lcd.setCursor(0, 1); lcd.print(" Version 1.0 ");
lcd.setCursor(0, 2); lcd.print("Southern Luzon State");
lcd.setCursor(0, 3); lcd.print(" University ");
// Keypad Button Setup
pinMode(UP, INPUT_PULLUP);
pinMode(DOWN, INPUT_PULLUP);
pinMode(LEFT, INPUT_PULLUP);
pinMode(RIGHT, INPUT_PULLUP);
pinMode(ENTER, INPUT_PULLUP);
delay(1000);
parametersMainScreen();
}
void loop() {
// Move Left
if (digitalRead(LEFT) == LOW) {
moveLeft();
delay(300);
}
// Move Right
if (digitalRead(RIGHT) == LOW) {
moveRight();
delay(300);
}
// Enter Selection
if (digitalRead(ENTER) == LOW) {
selectOption();
delay(300);
}
}
// Display Parameters Screen
void parametersMainScreen() {
lcd.clear();
lcd.backlight();
// Display Titles
lcd.setCursor(0, 0); lcd.print(" Parameters ");
// Display Values
lcd.setCursor(0, 1); lcd.print("V= "); lcd.print(voltage); lcd.print("V HI= "); lcd.print(holeInterval); lcd.print("ft.");
lcd.setCursor(0, 2); lcd.print("L= "); lcd.print(plotDistance); lcd.print("ft. SL= "); lcd.print(movementSpeed); lcd.print("%");
// Display Menu Options
lcd.setCursor(0, 3);
for (int i = 0; i < menuSize; i++) {
if (i == currentParametersOption) {
lcd.print(">"); // Highlight current selection
} else {
lcd.print(" ");
}
lcd.print(option[i]);
lcd.print(" "); // Space between options
}
}
// Move Selection Left
void moveLeft() {
if (currentParametersOption == 0) {
currentParametersOption = menuSize - 1; // Loop back to last option
} else {
currentParametersOption--; // Move left
}
parametersMainScreen(); // Refresh LCD
}
// Move Selection Right
void moveRight() {
if (currentParametersOption == menuSize - 1) {
currentParametersOption = 0; // Loop back to first option
} else {
currentParametersOption++; // Move right
}
parametersMainScreen(); // Refresh LCD
}
// Select Current Option
void selectOption() {
lcd.clear();
lcd.setCursor(4, 1);
lcd.print("Selected:");
lcd.setCursor(8, 2);
lcd.print(option[currentParametersOption]);
delay(2000); // Display selection confirmation
parametersMainScreen(); // Return to menu
}