#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
// Initialize keypad
const byte ROWS = 4; // Number of rows on the keypad
const byte COLS = 4; // Number of columns on the keypad
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {13, 12, 14, 27};
byte colPins[COLS] = {26, 25, 33, 32};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Initialize LCD
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Welcome Press");
lcd.setCursor(0, 1);
lcd.print(" D for Menu");
}
void loop() {
char key = keypad.getKey();
if (key) {
if (key == 'D') {
showMenu();
}
}
}
void showMenu() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("1: Design Create");
lcd.setCursor(0, 1);
lcd.print("2: Saved Design");
char key;
while (true) {
key = keypad.getKey();
if (key) {
handleMenuInput(key);
break;
}
}
}
void handleMenuInput(char key) {
switch (key) {
case '1': {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Repeat Size:");
int repeatSize = getInput(); // Get user input for repeat size
int box1Picks, box2Picks, box3Picks, box4Picks;
// Get picks for each box
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Box 1 Picks:");
box1Picks = getInput();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Box 2 Picks:");
box2Picks = getInput();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Box 3 Picks:");
box3Picks = getInput();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Box 4 Picks:");
box4Picks = getInput();
// Check if total picks match the repeat size
int totalPicks = box1Picks + box2Picks + box3Picks + box4Picks;
if (totalPicks == repeatSize) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Design Saved!");
} else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Error: Total Picks");
lcd.setCursor(0, 1);
lcd.print("!= Repeat Size");
delay(2000);
}
delay(1000); // Allow the user to see the confirmation
break;
}
case '2': {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Saved Design");
int savedDesign = getInput(); // Get user input for saved design number
break;
}
default: {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Invalid Option");
delay(1000);
showMenu();
break;
}
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Welcome to Power");
lcd.setCursor(0, 1);
lcd.print("Loom Press D for");
lcd.setCursor(0, 2);
lcd.print("Menu");
}
int getInput() {
String input = "";
char key;
while (true) {
key = keypad.getKey();
if (key && key >= '0' && key <= '9') {
input += key;
lcd.print(key);
}
if (key == '#') { // # is the Enter key
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Settings Saved!");
delay(1000); // Display "Settings Saved!" for 1 second
break;
}
}
return input.toInt();
}