Advertisement
pleasedontcode

Button Detection rev_01

Feb 28th, 2024
74
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 Detection
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-02-28 18:19:09
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The system shall detect button press events on pin */
  21.     /* D2 and trigger a corresponding action. */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <EasyButton.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void buttonPressed();
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t BUTTON_PIN = 2;
  34.  
  35. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  36. EasyButton button(BUTTON_PIN); // Instantiate the EasyButton object
  37.  
  38. void setup(void)
  39. {
  40.   // put your setup code here, to run once:
  41.  
  42.   button.begin(); // Initialize the button
  43.  
  44.   // Set up your button callbacks here
  45.  
  46.   // System Requirement 1: Detect button press events and trigger corresponding action
  47.   button.onPressed(buttonPressed);
  48. }
  49.  
  50. void loop(void)
  51. {
  52.   // put your main code here, to run repeatedly:
  53.  
  54.   button.read(); // Read the button state
  55. }
  56.  
  57. void buttonPressed()
  58. {
  59.   // Code to be executed when the button is pressed
  60.   // Implement the action triggered by the button press event
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement