Advertisement
pleasedontcode

"Button Navigation" rev_11

Jun 7th, 2024
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Button Navigation"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-06-07 10:35:14
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* lcd display i2c  20x4  button pin11 UP LOW menu up */
  21.     /* button pin10 UP LOW menu enter  button pin12UP LOW */
  22.     /* menu down  menu   MaxTemp ->max_temp -= 1.0; */
  23.     /* MinTeamp->min_temp -= 1.0;  menu   MaxFlow -> */
  24.     /* MinFlow -> */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Wire.h>
  29. #include <LiquidCrystal_I2C.h>  // https://github.com/marcoschwartz/LiquidCrystal_I2C
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateMenu(void);
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t UP_BUTTON_PushButton_PIN_D11 = 11;
  38. const uint8_t DOWN_BUTTON_PushButton_PIN_D12 = 12;
  39. const uint8_t ENTER_BUTTON_PushButton_PIN_D10 = 10;
  40.  
  41. /****** DEFINITION OF VARIABLES *****/
  42. float max_temp = 100.0;
  43. float min_temp = 0.0;
  44. float max_flow = 10.0;
  45. float min_flow = 1.0;
  46. int menu_index = 0;
  47.  
  48. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  49. LiquidCrystal_I2C lcd(0x27, 20, 4);  // set the LCD address to 0x27 for a 20 chars and 4 line display
  50.  
  51. void setup(void)
  52. {
  53.     // put your setup code here, to run once:
  54.  
  55.     pinMode(UP_BUTTON_PushButton_PIN_D11, INPUT_PULLUP);
  56.     pinMode(DOWN_BUTTON_PushButton_PIN_D12, INPUT_PULLUP);
  57.     pinMode(ENTER_BUTTON_PushButton_PIN_D10, INPUT_PULLUP);
  58.  
  59.     // Initialize the LCD
  60.     lcd.init();
  61.     lcd.backlight();
  62.  
  63.     // Print a message to the LCD
  64.     lcd.setCursor(3, 0);
  65.     lcd.print("Hello, world!");
  66.     lcd.setCursor(2, 1);
  67.     lcd.print("Ywrobot Arduino!");
  68.     lcd.setCursor(0, 2);
  69.     lcd.print("Arduino LCM IIC 2004");
  70.     lcd.setCursor(2, 3);
  71.     lcd.print("Power By Ec-yuan!");
  72. }
  73.  
  74. void loop(void)
  75. {
  76.     // put your main code here, to run repeatedly:
  77.     updateMenu();
  78. }
  79.  
  80. void updateMenu(void)
  81. {
  82.     if (digitalRead(UP_BUTTON_PushButton_PIN_D11) == LOW)
  83.     {
  84.         menu_index--;
  85.         if (menu_index < 0) menu_index = 3;
  86.         delay(200); // debounce delay
  87.     }
  88.     else if (digitalRead(DOWN_BUTTON_PushButton_PIN_D12) == LOW)
  89.     {
  90.         menu_index++;
  91.         if (menu_index > 3) menu_index = 0;
  92.         delay(200); // debounce delay
  93.     }
  94.     else if (digitalRead(ENTER_BUTTON_PushButton_PIN_D10) == LOW)
  95.     {
  96.         switch (menu_index)
  97.         {
  98.             case 0:
  99.                 max_temp -= 1.0;
  100.                 break;
  101.             case 1:
  102.                 min_temp -= 1.0;
  103.                 break;
  104.             case 2:
  105.                 max_flow -= 1.0;
  106.                 break;
  107.             case 3:
  108.                 min_flow -= 1.0;
  109.                 break;
  110.         }
  111.         delay(200); // debounce delay
  112.     }
  113.  
  114.     lcd.clear();
  115.     lcd.setCursor(0, 0);
  116.     lcd.print("Menu:");
  117.     lcd.setCursor(0, 1);
  118.     lcd.print(menu_index == 0 ? "> MaxTemp" : "  MaxTemp");
  119.     lcd.setCursor(0, 2);
  120.     lcd.print(menu_index == 1 ? "> MinTemp" : "  MinTemp");
  121.     lcd.setCursor(0, 3);
  122.     lcd.print(menu_index == 2 ? "> MaxFlow" : "  MaxFlow");
  123.     lcd.setCursor(0, 4);
  124.     lcd.print(menu_index == 3 ? "> MinFlow" : "  MinFlow");
  125. }
  126.  
  127. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement