Advertisement
pleasedontcode

Button Handler rev_01

Mar 27th, 2024
94
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 Handler
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-27 18:08:12
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* As a user, I want to be able to detect when the */
  21.     /* push button connected to pin D2 is pressed, so */
  22.     /* that I can trigger an action in my Arduino */
  23.     /* project. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <EasyButton.h>    // Third-party library for easy button handling
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup();
  31. void loop();
  32. void onButtonPress();  // TODO: Add callback function for button press event
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t buttonPin = 2;  // Pin connected to the push button (D2)
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. EasyButton button(buttonPin);  // Initialize EasyButton object
  39.  
  40. void setup()
  41. {
  42.   // TODO: Initialize any additional GPIO or peripherals
  43.  
  44.   pinMode(buttonPin, INPUT_PULLUP);  // Configure push button pin
  45.  
  46.   button.begin();  // Begin button library
  47.  
  48.   // Add callback function to be triggered when button is pressed
  49.   button.onPressed(onButtonPress);
  50. }
  51.  
  52. void loop()
  53. {
  54.   // Continue reading button state
  55.   button.read();
  56.  
  57.   // Your main code here
  58.  
  59.  
  60. }
  61.  
  62. void onButtonPress()
  63. {
  64.   // Action to be triggered when button is pressed
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement