Advertisement
pleasedontcode

"Button Navigation" rev_12

Jun 7th, 2024
288
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:38:30
  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  MaxTemp ->max_temp -= 1.0; */
  23.     /* MinTeamp->min_temp -= 1.0;  MaxFlow ->max_flow -= */
  24.     /* 1.0;  MinFlow ->min_flow -= 1.0; */
  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.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t UP_BUTTON_PushButton_PIN_D11 = 11;
  37. const uint8_t DOWN_BUTTON_PushButton_PIN_D12 = 12;
  38. const uint8_t ENTER_BUTTON_PushButton_PIN_D10 = 10;
  39.  
  40. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  41. LiquidCrystal_I2C lcd(0x27, 20, 4);  // set the LCD address to 0x27 for a 20 chars and 4 line display
  42.  
  43. /****** GLOBAL VARIABLES *****/
  44. float max_temp = 100.0;
  45. float min_temp = 0.0;
  46. float max_flow = 100.0;
  47. float min_flow = 0.0;
  48. int menu_index = 0;
  49.  
  50. void setup(void)
  51. {
  52.     // put your setup code here, to run once:
  53.  
  54.     pinMode(UP_BUTTON_PushButton_PIN_D11, INPUT_PULLUP);
  55.     pinMode(DOWN_BUTTON_PushButton_PIN_D12, INPUT_PULLUP);
  56.     pinMode(ENTER_BUTTON_PushButton_PIN_D10, INPUT_PULLUP);
  57.  
  58.     // Initialize the LCD
  59.     lcd.init();
  60.     lcd.backlight();
  61.  
  62.     // Display a welcome message
  63.     lcd.setCursor(3, 0);
  64.     lcd.print("Hello, world!");
  65.     lcd.setCursor(2, 1);
  66.     lcd.print("Ywrobot Arduino!");
  67.     lcd.setCursor(0, 2);
  68.     lcd.print("Arduino LCM IIC 2004");
  69.     lcd.setCursor(2, 3);
  70.     lcd.print("Power By Ec-yuan!");
  71.     delay(2000);  // Display the welcome message for 2 seconds
  72.     lcd.clear();
  73. }
  74.  
  75. void loop(void)
  76. {
  77.     // put your main code here, to run repeatedly:
  78.  
  79.     if (digitalRead(UP_BUTTON_PushButton_PIN_D11) == LOW) {
  80.         menu_index--;
  81.         if (menu_index < 0) menu_index = 3;
  82.         delay(200);  // Debounce delay
  83.     }
  84.  
  85.     if (digitalRead(DOWN_BUTTON_PushButton_PIN_D12) == LOW) {
  86.         menu_index++;
  87.         if (menu_index > 3) menu_index = 0;
  88.         delay(200);  // Debounce delay
  89.     }
  90.  
  91.     if (digitalRead(ENTER_BUTTON_PushButton_PIN_D10) == LOW) {
  92.         switch (menu_index) {
  93.             case 0:
  94.                 max_temp -= 1.0;
  95.                 break;
  96.             case 1:
  97.                 min_temp -= 1.0;
  98.                 break;
  99.             case 2:
  100.                 max_flow -= 1.0;
  101.                 break;
  102.             case 3:
  103.                 min_flow -= 1.0;
  104.                 break;
  105.         }
  106.         delay(200);  // Debounce delay
  107.     }
  108.  
  109.     // Display the current menu and values
  110.     lcd.clear();
  111.     switch (menu_index) {
  112.         case 0:
  113.             lcd.setCursor(0, 0);
  114.             lcd.print("MaxTemp: ");
  115.             lcd.print(max_temp);
  116.             break;
  117.         case 1:
  118.             lcd.setCursor(0, 0);
  119.             lcd.print("MinTemp: ");
  120.             lcd.print(min_temp);
  121.             break;
  122.         case 2:
  123.             lcd.setCursor(0, 0);
  124.             lcd.print("MaxFlow: ");
  125.             lcd.print(max_flow);
  126.             break;
  127.         case 3:
  128.             lcd.setCursor(0, 0);
  129.             lcd.print("MinFlow: ");
  130.             lcd.print(min_flow);
  131.             break;
  132.     }
  133.     delay(100);  // Small delay to avoid flickering
  134. }
  135.  
  136. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement