Advertisement
pleasedontcode

Button Callbacks rev_01

Mar 19th, 2024
76
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 compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-19 18:22:44
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The system shall detect button press events on */
  21.     /* pins D2 and D3 using the EasyButton library. */
  22. /****** SYSTEM REQUIREMENT 2 *****/
  23.     /* The system shall detect button press events on */
  24.     /* pins D2 and D3 using the EasyButton library. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <EasyButton.h>
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup();
  32. void loop();
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t BUTTON_ONE_PIN = 2;
  36. const uint8_t BUTTON_TWO_PIN = 3;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. EasyButton button1(BUTTON_ONE_PIN);
  40. EasyButton button2(BUTTON_TWO_PIN);
  41.  
  42. void onButton1Pressed()
  43. {
  44.     // Callback function when button1 is pressed
  45.     Serial.println("Button1 pressed");
  46. }
  47.  
  48. void onButton2Pressed()
  49. {
  50.     // Callback function when button2 is pressed
  51.     Serial.println("Button2 pressed");
  52. }
  53.  
  54. void setup()
  55. {
  56.     // put your setup code here, to run once:
  57.     Serial.begin(9600);
  58.  
  59.     // Initialize the buttons
  60.     button1.begin();
  61.     button2.begin();
  62.  
  63.     // Assign the callback functions to the buttons
  64.     button1.onPressed(onButton1Pressed);
  65.     button2.onPressed(onButton2Pressed);
  66. }
  67.  
  68. void loop()
  69. {
  70.     // put your main code here, to run repeatedly:
  71.     button1.read();
  72.     button2.read();
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement