/********* 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 10:35:14
********* 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 menu MaxTemp ->max_temp -= 1.0; */
/* MinTeamp->min_temp -= 1.0; menu MaxFlow -> */
/* MinFlow -> */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include
#include // https://github.com/marcoschwartz/LiquidCrystal_I2C
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateMenu(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 VARIABLES *****/
float max_temp = 100.0;
float min_temp = 0.0;
float max_flow = 10.0;
float min_flow = 1.0;
int menu_index = 0;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 20 chars and 4 line display
void setup(void)
{
// put your setup code here, to run once:
pinMode(UP_BUTTON_PushButton_PIN_D11, INPUT_PULLUP);
pinMode(DOWN_BUTTON_PushButton_PIN_D12, INPUT_PULLUP);
pinMode(ENTER_BUTTON_PushButton_PIN_D10, INPUT_PULLUP);
// Initialize the LCD
lcd.init();
lcd.backlight();
// Print a message to the LCD
lcd.setCursor(3, 0);
lcd.print("Hello, world!");
lcd.setCursor(2, 1);
lcd.print("Ywrobot Arduino!");
lcd.setCursor(0, 2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2, 3);
lcd.print("Power By Ec-yuan!");
}
void loop(void)
{
// put your main code here, to run repeatedly:
updateMenu();
}
void updateMenu(void)
{
if (digitalRead(UP_BUTTON_PushButton_PIN_D11) == LOW)
{
menu_index--;
if (menu_index < 0) menu_index = 3;
delay(200); // debounce delay
}
else if (digitalRead(DOWN_BUTTON_PushButton_PIN_D12) == LOW)
{
menu_index++;
if (menu_index > 3) menu_index = 0;
delay(200); // debounce delay
}
else if (digitalRead(ENTER_BUTTON_PushButton_PIN_D10) == LOW)
{
switch (menu_index)
{
case 0:
max_temp -= 1.0;
break;
case 1:
min_temp -= 1.0;
break;
case 2:
max_flow -= 1.0;
break;
case 3:
min_flow -= 1.0;
break;
}
delay(200); // debounce delay
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Menu:");
lcd.setCursor(0, 1);
lcd.print(menu_index == 0 ? "> MaxTemp" : " MaxTemp");
lcd.setCursor(0, 2);
lcd.print(menu_index == 1 ? "> MinTemp" : " MinTemp");
lcd.setCursor(0, 3);
lcd.print(menu_index == 2 ? "> MaxFlow" : " MaxFlow");
lcd.setCursor(0, 4);
lcd.print(menu_index == 3 ? "> MinFlow" : " MinFlow");
}
/* END CODE */