/* ezButton_Calss_and_Menu.ino
*
* Simple hotplate controller using Arduino
* by : Rilles Eko Prianto
* January 18, 2023
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <ezButton.h>
enum mode{MODE_OFF, MODE_START, MODE_NORMAL, MODE_RAMP_UP, MODE_COOLING};
char * status[5] = {"OFF ","STARTING ","HEATING UP","RAMP UP ","COOLING "};
byte relay = 5;
byte ssr = 6;
byte state;
byte sensor = A0;
bool btnState = 0;
bool btnLastState;
byte menu = 0;
short temperature = 0;
unsigned long lastTime, currentTime = 0;
ezButton btn1(3), btn2(4);
mode md = 0;
LiquidCrystal_I2C lcd(0x3C,16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup() {
pinMode(relay, OUTPUT);
pinMode(ssr, OUTPUT);
// btnLastState = btn1.state();
// Serial.begin(9600);
btn1.setDebounceTime(30);
lcd.init(); // initialize the lcd
lcd.backlight();
//lcd.print("0123456789012345");
disp(0,0, " RILLES FOTO", false);
disp(0,1, "DIGITAL PROJECTS", false);
delay(500);
lcd.clear();
disp(0,0, "TEMP:", false);
disp(9,0, "SET:", false);
disp(0,1, status[state], false);
}
void disp(byte x, byte y, char* teks, bool clr){
lcd.setCursor(x,y);
if(clr) {
lcd.clear();
}
// lcd.print("0123456789012345");
lcd.print(teks);
}
void loop() {
btn1.loop();
if (btn1.isPressed()){
lastTime = millis();
// Serial.print("The button is pressed\t");
// Serial.println(lastTime);
}
if (btn1.isReleased()){
currentTime = millis();
// Serial.print("The button is released\t");
// Serial.println(currentTime);
if (currentTime-lastTime <800){
// Serial.print("\t");
// Serial.println(currentTime-lastTime);
if (menu>0){
menu++;
}
} else {
if (menu>0){
menu=0;
} else {
menu = 1;
}
}
}
updateMenu();
}
void updateMenu(){
if (menu==5) menu = 1;
md = menu;
disp(0,1, status[menu], false);
switch (md){
case MODE_OFF: // OFF
break;
case MODE_START: // STARTING
break;
case MODE_NORMAL: // HEATING UP
break;
case MODE_RAMP_UP: // RAMP UP
break;
case MODE_COOLING: // COOLING
break;
}
}