Advertisement
pleasedontcode

"Button Presses" rev_02

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