/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: "Button Navigation"
- Source Code NOT compiled for: Arduino Uno
- Source Code created on: 2024-06-07 04:13:09
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* lcd display i2c 20x4 button pin11 UP LOW menu up */
/* button pin10 UP LOW menu enter button pin12UP LOW */
/* menu down Temperatur submenu MaxTemp */
/* ->max_temp -= 0.1; MinTeamp->min_temp -= 0.1; */
/* Durchfluss(Flow) submenu MaxFlow -> MinFlow -> */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include //https://github.com/evert-arias/EasyButton
#include //https://github.com/marcoschwartz/LiquidCrystal_I2C
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t UP_BUTTON_PushButton_PIN_D11 = 11;
const uint8_t DOWN_BUTTON_PushButton_PIN_D12 = 12;
const uint8_t ENTER_BUTTON_PushButton_PIN_D10 = 10;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
EasyButton buttonUp(UP_BUTTON_PushButton_PIN_D11);
EasyButton buttonDown(DOWN_BUTTON_PushButton_PIN_D12);
EasyButton buttonEnter(ENTER_BUTTON_PushButton_PIN_D10);
// Initialize the LCD with the I2C address 0x27 and a 20x4 display
LiquidCrystal_I2C lcd(0x27, 20, 4);
/****** VARIABLES FOR MENU *****/
float max_temp = 100.0;
float min_temp = 0.0;
float max_flow = 10.0;
float min_flow = 0.0;
int menu_index = 0;
int submenu_index = 0;
bool in_submenu = false;
/****** CALLBACK FUNCTIONS *****/
void onButtonUpPressed() {
if (in_submenu) {
if (submenu_index == 0) {
max_temp -= 0.1;
} else if (submenu_index == 1) {
min_temp -= 0.1;
} else if (submenu_index == 2) {
max_flow -= 0.1;
} else if (submenu_index == 3) {
min_flow -= 0.1;
}
} else {
menu_index = (menu_index - 1 + 4) % 4; // Wrap around menu index
}
updateLCD();
}
void onButtonDownPressed() {
if (in_submenu) {
if (submenu_index == 0) {
max_temp += 0.1;
} else if (submenu_index == 1) {
min_temp += 0.1;
} else if (submenu_index == 2) {
max_flow += 0.1;
} else if (submenu_index == 3) {
min_flow += 0.1;
}
} else {
menu_index = (menu_index + 1) % 4; // Wrap around menu index
}
updateLCD();
}
void onButtonEnterPressed() {
if (!in_submenu) {
in_submenu = true;
submenu_index = menu_index;
} else {
in_submenu = false;
}
updateLCD();
}
void updateLCD() {
lcd.clear();
if (!in_submenu) {
lcd.setCursor(0, 0);
lcd.print("Menu:");
lcd.setCursor(0, 1);
lcd.print(menu_index == 0 ? "> Max Temp" : " Max Temp");
lcd.setCursor(0, 2);
lcd.print(menu_index == 1 ? "> Min Temp" : " Min Temp");
lcd.setCursor(0, 3);
lcd.print(menu_index == 2 ? "> Max Flow" : " Max Flow");
lcd.setCursor(0, 4);
lcd.print(menu_index == 3 ? "> Min Flow" : " Min Flow");
} else {
lcd.setCursor(0, 0);
if (submenu_index == 0) {
lcd.print("Max Temp: ");
lcd.print(max_temp);
} else if (submenu_index == 1) {
lcd.print("Min Temp: ");
lcd.print(min_temp);
} else if (submenu_index == 2) {
lcd.print("Max Flow: ");
lcd.print(max_flow);
} else if (submenu_index == 3) {
lcd.print("Min Flow: ");
lcd.print(min_flow);
}
}
}
void setup(void) {
// Initialize serial communication
Serial.begin(115200);
// Initialize buttons
buttonUp.begin();
buttonDown.begin();
buttonEnter.begin();
// Attach callback functions to buttons
buttonUp.onPressed(onButtonUpPressed);
buttonDown.onPressed(onButtonDownPressed);
buttonEnter.onPressed(onButtonEnterPressed);
// Initialize the LCD
lcd.init();
lcd.backlight();
updateLCD();
// Set pin modes for buttons
pinMode(UP_BUTTON_PushButton_PIN_D11, INPUT_PULLUP);
pinMode(DOWN_BUTTON_PushButton_PIN_D12, INPUT_PULLUP);
pinMode(ENTER_BUTTON_PushButton_PIN_D10, INPUT_PULLUP);
}
void loop(void) {
// Read button states
buttonUp.read();
buttonDown.read();
buttonEnter.read();
// Your main code here, to run repeatedly:
}
/* END CODE */