Advertisement
pleasedontcode

Button Handling rev_01

Jun 3rd, 2024
347
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 Handling
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-06-03 10:57:32
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop an Arduino project using EasyButton */
  21.     /* library to manage three push buttons connected to */
  22.     /* pins D2, D3, and D4. The project should initialize */
  23.     /* these pins with INPUT_PULLUP mode and include */
  24.     /* basic setup and loop functions. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <EasyButton.h>  // https://github.com/evert-arias/EasyButton
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void onButton1Pressed(void);
  34. void onButton2Pressed(void);
  35. void onButton3Pressed(void);
  36.  
  37. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  38. const uint8_t mani_PushButton_PIN_D2 = 2;
  39. const uint8_t mani_PushButton_PIN_D3 = 3;
  40. const uint8_t mani_PushButton_PIN_D4 = 4;
  41.  
  42. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  43. EasyButton button1(mani_PushButton_PIN_D2);  // Initialize EasyButton object for button 1
  44. EasyButton button2(mani_PushButton_PIN_D3);  // Initialize EasyButton object for button 2
  45. EasyButton button3(mani_PushButton_PIN_D4);  // Initialize EasyButton object for button 3
  46.  
  47. void setup(void)
  48. {
  49.     // Initialize serial communication at 115200 baud rate
  50.     Serial.begin(115200);
  51.  
  52.     Serial.println();
  53.     Serial.println(">>> EasyButton multiple buttons example <<<");
  54.  
  55.     // Initialize buttons
  56.     button1.begin();
  57.     button2.begin();
  58.     button3.begin();
  59.  
  60.     // Attach callback functions to be called when buttons are pressed
  61.     button1.onPressed(onButton1Pressed);
  62.     button2.onPressed(onButton2Pressed);
  63.     button3.onPressed(onButton3Pressed);
  64. }
  65.  
  66. void loop(void)
  67. {
  68.     // Continuously read the button states
  69.     button1.read();
  70.     button2.read();
  71.     button3.read();
  72. }
  73.  
  74. // Callback function for button 1 press
  75. void onButton1Pressed(void)
  76. {
  77.     Serial.println("Button1 pressed");
  78. }
  79.  
  80. // Callback function for button 2 press
  81. void onButton2Pressed(void)
  82. {
  83.     Serial.println("Button2 pressed");
  84. }
  85.  
  86. // Callback function for button 3 press
  87. void onButton3Pressed(void)
  88. {
  89.     Serial.println("Button3 pressed");
  90. }
  91.  
  92. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement