Advertisement
pleasedontcode

"Button Messages" rev_02

Jun 6th, 2024
329
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 Messages"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-06-07 03:53:06
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* lcd display i2c  20x4   button pin11 INPUT_PULLUP */
  21.     /* LOW menu up  button pin10 INPUT_PULLUP LOW menu */
  22.     /* enter  button pin12 INPUT_PULLUP   LOW  menu down */
  23.     /* startmenu  test1  test2  submenu test1  lol1  lol2 */
  24.     /* sub menu test2  ha1  ha2 */
  25. /****** SYSTEM REQUIREMENT 2 *****/
  26.     /* lcd display i2c  20x4  button pin11 UPLOW menu up */
  27.     /* button pin10 UP LOW menu enter  button pin12UP LOW */
  28.     /* menu down  Temperatur->MaxTemp->code */
  29.     /* ->MinTeamp->code  Durchfluss(Flow)->MaxFlow->code */
  30.     /* ->MinTeamp->code */
  31. /****** END SYSTEM REQUIREMENTS *****/
  32.  
  33. /****** DEFINITION OF LIBRARIES *****/
  34. #include <EasyButton.h>  //https://github.com/evert-arias/EasyButton
  35. #include <Wire.h>
  36. #include <LiquidCrystal_I2C.h>
  37.  
  38. /****** FUNCTION PROTOTYPES *****/
  39. void setup(void);
  40. void loop(void);
  41. void onUpButtonPressed();
  42. void onDownButtonPressed();
  43. void onEnterButtonPressed();
  44.  
  45. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  46. const uint8_t UP_BUTTON_PIN = 11;
  47. const uint8_t DOWN_BUTTON_PIN = 12;
  48. const uint8_t ENTER_BUTTON_PIN = 10;
  49.  
  50. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  51. EasyButton upButton(UP_BUTTON_PIN, 35, true, false);   // Initialize EasyButton instance for UP button
  52. EasyButton downButton(DOWN_BUTTON_PIN, 35, true, false); // Initialize EasyButton instance for DOWN button
  53. EasyButton enterButton(ENTER_BUTTON_PIN, 35, true, false); // Initialize EasyButton instance for ENTER button
  54.  
  55. LiquidCrystal_I2C lcd(0x27, 20, 4); // Set the LCD I2C address to 0x27 for a 20 chars and 4 line display
  56.  
  57. void setup(void)
  58. {
  59.   // put your setup code here, to run once:
  60.   Serial.begin(115200);
  61.  
  62.   lcd.init();                      // initialize the lcd
  63.   lcd.backlight();
  64.   lcd.setCursor(0,0);
  65.   lcd.print("System Initializing");
  66.  
  67.   Serial.println();
  68.   Serial.println(">>> EasyButton multiple buttons example <<<");
  69.  
  70.   upButton.begin();
  71.   downButton.begin();
  72.   enterButton.begin();
  73.  
  74.   upButton.onPressed(onUpButtonPressed);
  75.   downButton.onPressed(onDownButtonPressed);
  76.   enterButton.onPressed(onEnterButtonPressed);
  77. }
  78.  
  79. void loop(void)
  80. {
  81.   // put your main code here, to run repeatedly:
  82.   upButton.read();
  83.   downButton.read();
  84.   enterButton.read();
  85. }
  86.  
  87. void onUpButtonPressed() {
  88.   Serial.println("Up button pressed");
  89.   lcd.clear();
  90.   lcd.setCursor(0,0);
  91.   lcd.print("Up button pressed");
  92. }
  93.  
  94. void onDownButtonPressed() {
  95.   Serial.println("Down button pressed");
  96.   lcd.clear();
  97.   lcd.setCursor(0,0);
  98.   lcd.print("Down button pressed");
  99. }
  100.  
  101. void onEnterButtonPressed() {
  102.   Serial.println("Enter button pressed");
  103.   lcd.clear();
  104.   lcd.setCursor(0,0);
  105.   lcd.print("Enter button pressed");
  106. }
  107.  
  108. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement