Hi, I'm trying to make a menu system but I'm having problems transitioning to cases.
currently I only made 3 cases:
- main menu (choose between, sales (to print total coins inserted), retail (to change price) wholesale (to change price) and timer (to change duration)
- retail menu
- timer menu
I have no problem going from case 1 to 2 and v.v. but when i go to case 3 the lcd just goes blank.
int minus = 4;
int plus = 5;
int ok = 6;
int ss_state;
unsigned long i;
int pointer = 1;
float price = 10;
unsigned long timer = 5000;
#include <Wire.h>;
#include <LiquidCrystal_I2C.h>;
LiquidCrystal_I2C lcd(0x27, 20, 4);
uint8_t check[8] = {0x0, 0x1, 0x3, 0x16, 0x1c, 0x8, 0x0};
void setup() {
// put your setup code here, to run once:
pinMode(minus, INPUT);
pinMode(plus, INPUT);
pinMode(ok, INPUT);
Serial.begin(9600);
lcd.createChar(5, check);
#define printByte(args) write(args);
lcd.init();
lcd.backlight();
ss_state = 1;
}
void loop() {
ss();
}
void ss() {
switch (ss_state) {
case 1:
//lcd.setCursor(0,0);
//lcd.print(pointer);
//lcd.setCursor(1,0);
//lcd.print(ss_state);
lcd.setCursor(8, 0);
lcd.print("MENU");
lcd.setCursor(1, 1);
lcd.print("SALES");
lcd.setCursor(13, 1);
lcd.print("RETAIL");
lcd.setCursor(1, 3);
lcd.print("WHOLESALE");
lcd.setCursor(13, 3);
lcd.print("TIMER");
i++;
if (digitalRead(minus) == HIGH && i >= 5) {
pointer = pointer - 1;
i = 0;
delay(5);
}
if (digitalRead(plus) == HIGH && i >= 5) {
pointer = pointer + 1;
i = 0;
delay(5);
}
if (pointer == 1) {
lcd.setCursor(12, 3);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.printByte(5);
}
if (pointer == 2) {
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(12, 1);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.printByte(5);
}
if (pointer == 3) {
lcd.setCursor(0, 3);
lcd.print(" ");
lcd.setCursor(12, 3);
lcd.print(" ");
lcd.setCursor(12, 1);
lcd.printByte(5);
}
if (pointer == 4) {
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(12, 1);
lcd.print(" ");
lcd.setCursor(12, 3);
lcd.printByte(5);
}
if (pointer >= 5) {
pointer = 1;
}
if (pointer <= 0) {
pointer = 4;
}
if (digitalRead(ok) == HIGH && pointer == 3 && i >= 5) {
lcd.clear();
ss_state = 2;
delay(250);
}
if (digitalRead(ok) == HIGH && pointer == 4 && i >= 5) {
lcd.clear();
ss_state = 3;
delay(250);
}
break;
case 2:
i++;
float one = 1;
lcd.setCursor(2, 0);
lcd.print("SET RETAIL PRICE");
lcd.setCursor(8, 2);
lcd.print(price);
if (digitalRead(plus) == HIGH && i >= 5) {
price = price + one;
delay(250);
}
if (digitalRead(minus) == HIGH && i >= 5) {
price = price - one;
delay(250);
}
if (digitalRead(ok) == HIGH && i >= 5) {
lcd.clear();
ss_state = 1;
delay(250);
}
break;
case 3:
i++;
lcd.setCursor(6, 0);
lcd.print("SET TIMER");
lcd.setCursor(13, 2);
lcd.print(timer / 1000);
lcd.setCursor(15, 2);
lcd.print("sec");
if (digitalRead(plus) == HIGH && i >= 5) {
timer = timer + 1000;
delay(250);
}
if (digitalRead(minus) == HIGH && i >= 5) {
timer = timer - 1000;
delay(250);
}
if (digitalRead(ok) == HIGH && i >= 5) {
lcd.clear();
ss_state = 1;
delay(250);
}
break;
}
}