Advertisement
pleasedontcode

"Button Initialization" rev_06

Jun 6th, 2024
336
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 Initialization"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-06-07 04:06:28
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* lcd display i2c  20x4  button pin11 UPLOW menu up */
  21.     /* button pin10 UP LOW menu enter  button pin12UP LOW */
  22.     /* menu down  Temperatur  submenu   MaxTemp */
  23.     /* subsubmenu  MinTeamp subsubmenu  Durchfluss(Flow) */
  24.     /* submenu   MaxFlow subsubmenu  MinFlow subsubmenu */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <EasyButton.h> // https://github.com/evert-arias/EasyButton
  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 onUpButtonPressed();
  35. void onDownButtonPressed();
  36. void onEnterButtonPressed();
  37.  
  38. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  39. const uint8_t UP_BUTTON_PIN = 11;
  40. const uint8_t DOWN_BUTTON_PIN = 12;
  41. const uint8_t ENTER_BUTTON_PIN = 10;
  42.  
  43. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  44. EasyButton upButton(UP_BUTTON_PIN); // Initialize EasyButton for UP button
  45. EasyButton downButton(DOWN_BUTTON_PIN); // Initialize EasyButton for DOWN button
  46. EasyButton enterButton(ENTER_BUTTON_PIN); // Initialize EasyButton for ENTER button
  47.  
  48. // Initialize LiquidCrystal_I2C object with I2C address 0x27, 20 columns, and 4 rows
  49. LiquidCrystal_I2C lcd(0x27, 20, 4);
  50.  
  51. void setup(void) {
  52.   // put your setup code here, to run once:
  53.   Serial.begin(115200);
  54.  
  55.   // Initialize buttons
  56.   upButton.begin();
  57.   downButton.begin();
  58.   enterButton.begin();
  59.  
  60.   // Attach callbacks
  61.   upButton.onPressed(onUpButtonPressed);
  62.   downButton.onPressed(onDownButtonPressed);
  63.   enterButton.onPressed(onEnterButtonPressed);
  64.  
  65.   // Set pin modes
  66.   pinMode(UP_BUTTON_PIN, INPUT_PULLUP);
  67.   pinMode(DOWN_BUTTON_PIN, INPUT_PULLUP);
  68.   pinMode(ENTER_BUTTON_PIN, INPUT_PULLUP);
  69.  
  70.   // Initialize the LCD
  71.   lcd.init();
  72.   lcd.backlight();
  73.   lcd.setCursor(3, 0);
  74.   lcd.print("Hello, world!");
  75.   lcd.setCursor(2, 1);
  76.   lcd.print("Ywrobot Arduino!");
  77.   lcd.setCursor(0, 2);
  78.   lcd.print("Arduino LCM IIC 2004");
  79.   lcd.setCursor(2, 3);
  80.   lcd.print("Power By Ec-yuan!");
  81. }
  82.  
  83. void loop(void) {
  84.   // put your main code here, to run repeatedly:
  85.   upButton.read();
  86.   downButton.read();
  87.   enterButton.read();
  88. }
  89.  
  90. void onUpButtonPressed() {
  91.   Serial.println("Up button pressed");
  92. }
  93.  
  94. void onDownButtonPressed() {
  95.   Serial.println("Down button pressed");
  96. }
  97.  
  98. void onEnterButtonPressed() {
  99.   Serial.println("Enter button pressed");
  100. }
  101.  
  102. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement