#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Encoder.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Setup the encoder with the pins connected
Encoder myEnc(2, 3);
// Define the menus
String mainMenu[] = {"channel 1", "channel 2", "channel 3", "channel 4", "Start/Stop"};
String patternMenu[] = {"off", "DI", "stop", "Po / tail", "fog"};
// Variables to hold the current position in the menus
int mainMenuPos = 0;
int patternMenuPos = 0;
// Variables to hold the current state of the LEDs
bool ledState[] = {false, false, false, false};
void setup()
{
lcd.begin(16,2);
lcd.print("Welcome!");
delay(1000);
// Initialize the LED pins as outputs
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop()
{
// Check the encoder for changes
long newPos = myEnc.read();
if (newPos > mainMenuPos) {
mainMenuPos++;
if (mainMenuPos > 4) mainMenuPos = 0;
} else if (newPos < mainMenuPos) {
mainMenuPos--;
if (mainMenuPos < 0) mainMenuPos = 4;
}
// Display the current menu option
lcd.clear();
lcd.print(mainMenu[mainMenuPos]);
// Wait for a button press (assuming it's connected to pin 4)
if (digitalRead(4) == HIGH) {
// If a button press is detected, go into the pattern menu
while (digitalRead(4) == HIGH) {
// Same as above, but for the pattern menu
newPos = myEnc.read();
if (newPos > patternMenuPos) {
patternMenuPos++;
if (patternMenuPos > 4) patternMenuPos = 0;
} else if (newPos < patternMenuPos) {
patternMenuPos--;
if (patternMenuPos < 0) patternMenuPos = 4;
}
lcd.clear();
lcd.print(patternMenu[patternMenuPos]);
delay(100);
}
// After a pattern is selected, set the LED state for the selected channel
ledState[mainMenuPos] = patternMenuPos != 0; // The LED is off if the pattern is "off", on otherwise
}
// Update the LEDs
digitalWrite(8, ledState[0]);
digitalWrite(9, ledState[1]);
digitalWrite(10, ledState[2]);
digitalWrite(11, ledState[3]);
delay(100);
}