Advertisement
pleasedontcode

"Button Callbacks" rev_03

Jun 16th, 2024
538
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 Callbacks"
  13.     - Source Code NOT compiled for: Arduino Pro Mini 3.3V
  14.     - Source Code created on: 2024-06-16 13:22:18
  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.  
  28. /********* User code review feedback **********
  29. #### Feedback 1 ####
  30. - PYHON GAME COLORY
  31.  
  32. ********* User code review feedback **********/
  33.  
  34. /****** DEFINITION OF LIBRARIES *****/
  35. #include <EasyButton.h>  //https://github.com/evert-arias/EasyButton
  36.  
  37. /****** FUNCTION PROTOTYPES *****/
  38. void setup(void);
  39. void loop(void);
  40. void onButton1Pressed(void);
  41. void onButton2Pressed(void);
  42.  
  43. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  44. const uint8_t XXMX_PushButton_PIN_D2 = 2;
  45. const uint8_t XXMX_PushButton_PIN_D3 = 3;
  46.  
  47. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  48. EasyButton button1(XXMX_PushButton_PIN_D2);  // Initialize EasyButton object for button1
  49. EasyButton button2(XXMX_PushButton_PIN_D3);  // Initialize EasyButton object for button2
  50.  
  51. void onButton1Pressed() {
  52.   Serial.println("Button1 pressed");
  53. }
  54.  
  55. void onButton2Pressed() {
  56.   Serial.println("Button2 pressed");
  57. }
  58.  
  59. void setup(void) {
  60.   // Initialize serial communication
  61.   Serial.begin(115200);
  62.   Serial.println();
  63.   Serial.println(">>> EasyButton multiple buttons example <<<");
  64.  
  65.   // Initialize buttons
  66.   button1.begin();  // Initialize button1
  67.   button2.begin();  // Initialize button2
  68.  
  69.   // Attach callback functions for button presses
  70.   button1.onPressed(onButton1Pressed);  // Attach callback for button1
  71.   button2.onPressed(onButton2Pressed);  // Attach callback for button2
  72. }
  73.  
  74. void loop(void) {
  75.   // Continuously check the state of the buttons
  76.   button1.read();  // Read the state of button1
  77.   button2.read();  // Read the state of button2
  78. }
  79.  
  80. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement