Advertisement
pleasedontcode

"Button Press" rev_01

Jun 16th, 2024
478
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 Press"
  13.     - Source Code NOT compiled for: Arduino Pro Mini 3.3V
  14.     - Source Code created on: 2024-06-16 13:01:46
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implement a system to detect button presses using */
  21.     /* EasyButton library. Utilize digital pins D2 and D3 */
  22.     /* as input pins for two push buttons. Ensure the */
  23.     /* system initializes pins in setup() and */
  24.     /* continuously checks button states in loop(). */
  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.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t XXMX_PushButton_PIN_D2 = 2;
  38. const uint8_t XXMX_PushButton_PIN_D3 = 3;
  39.  
  40. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  41. EasyButton button1(XXMX_PushButton_PIN_D2);  // Initialize EasyButton object for button1
  42. EasyButton button2(XXMX_PushButton_PIN_D3);  // Initialize EasyButton object for button2
  43.  
  44. void onButton1Pressed() {
  45.   Serial.println("Button1 pressed");
  46. }
  47.  
  48. void onButton2Pressed() {
  49.   Serial.println("Button2 pressed");
  50. }
  51.  
  52. void setup(void) {
  53.   // Initialize serial communication
  54.   Serial.begin(115200);
  55.   Serial.println();
  56.   Serial.println(">>> EasyButton multiple buttons example <<<");
  57.  
  58.   // Initialize buttons
  59.   button1.begin();  // Initialize button1
  60.   button2.begin();  // Initialize button2
  61.  
  62.   // Attach callback functions for button presses
  63.   button1.onPressed(onButton1Pressed);  // Attach callback for button1
  64.   button2.onPressed(onButton2Pressed);  // Attach callback for button2
  65. }
  66.  
  67. void loop(void) {
  68.   // Continuously check the state of the buttons
  69.   button1.read();  // Read the state of button1
  70.   button2.read();  // Read the state of button2
  71. }
  72.  
  73. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement