Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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 03:57:12
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* lcd display i2c 20x4 button pin11 UPLOW menu up */
- /* button pin10 UP LOW menu enter button pin12UP LOW */
- /* menu down menu Temperatur->MaxTemp->code */
- /* ->MinTeamp->code Durchfluss(Flow)->MaxFlow->code */
- /* ->MinTeamp->code */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- #include <LiquidCrystal_I2C.h> //https://github.com/marcoschwartz/LiquidCrystal_I2C
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void onUpButtonPressed();
- void onDownButtonPressed();
- void onEnterButtonPressed();
- void displayMenu();
- /***** 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 I2C PINS *****/
- const uint8_t lcd_LCD2004I2C_I2C_SLAVE_ADDRESS = 0x27; // Corrected to 0x27 based on examples
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- EasyButton upButton(UP_BUTTON_PushButton_PIN_D11); // Initialize EasyButton for UP button
- EasyButton downButton(UP_BUTTON_PushButton_PIN_D12); // Initialize EasyButton for DOWN button
- EasyButton enterButton(ENTER_BUTTON_PushButton_PIN_D10); // Initialize EasyButton for ENTER button
- LiquidCrystal_I2C lcd(lcd_LCD2004I2C_I2C_SLAVE_ADDRESS, 20, 4); // Initialize LiquidCrystal_I2C for a 20x4 display
- /****** MENU VARIABLES *****/
- enum MenuOption { TEMPERATURE, MAX_TEMP, MIN_TEMP, FLOW, MAX_FLOW, MIN_FLOW };
- MenuOption currentMenu = TEMPERATURE;
- void setup(void)
- {
- // put your setup code here, to run once:
- Serial.begin(115200);
- 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 EasyButton instances
- upButton.begin();
- downButton.begin();
- enterButton.begin();
- // Attach callback functions to button press events
- upButton.onPressed(onUpButtonPressed);
- downButton.onPressed(onDownButtonPressed);
- enterButton.onPressed(onEnterButtonPressed);
- // Initialize the LCD
- lcd.init();
- lcd.backlight();
- displayMenu();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- upButton.read();
- downButton.read();
- enterButton.read();
- }
- // Callback functions for button presses
- void onUpButtonPressed() {
- Serial.println("UP button pressed");
- if (currentMenu == TEMPERATURE) {
- currentMenu = MIN_FLOW;
- } else {
- currentMenu = static_cast<MenuOption>(currentMenu - 1);
- }
- displayMenu();
- }
- void onDownButtonPressed() {
- Serial.println("DOWN button pressed");
- if (currentMenu == MIN_FLOW) {
- currentMenu = TEMPERATURE;
- } else {
- currentMenu = static_cast<MenuOption>(currentMenu + 1);
- }
- displayMenu();
- }
- void onEnterButtonPressed() {
- Serial.println("ENTER button pressed");
- // Implement code to handle the enter button press based on the current menu
- }
- void displayMenu() {
- lcd.clear();
- switch (currentMenu) {
- case TEMPERATURE:
- lcd.setCursor(0, 0);
- lcd.print("Menu: Temperature");
- break;
- case MAX_TEMP:
- lcd.setCursor(0, 0);
- lcd.print("Menu: MaxTemp");
- break;
- case MIN_TEMP:
- lcd.setCursor(0, 0);
- lcd.print("Menu: MinTemp");
- break;
- case FLOW:
- lcd.setCursor(0, 0);
- lcd.print("Menu: Flow");
- break;
- case MAX_FLOW:
- lcd.setCursor(0, 0);
- lcd.print("Menu: MaxFlow");
- break;
- case MIN_FLOW:
- lcd.setCursor(0, 0);
- lcd.print("Menu: MinFlow");
- break;
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement