Advertisement
pleasedontcode

"Button Detection" rev_01

Jun 30th, 2024
549
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 NOT compiled for: Arduino Pro Mini 3.3V
  14.     - Source Code created on: 2024-06-30 13:33:39
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop a system to detect button presses using an */
  21.     /* EasyButton library. The button is connected to */
  22.     /* digital pin D2. The system should initialize the */
  23.     /* button in the setup() function and continuously */
  24.     /* check for button presses in the loop() function. */
  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 onPressed(void);  // Prototype for the button press callback function
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t go_PushButton_PIN_D2 = 2;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. EasyButton button(go_PushButton_PIN_D2);  // Initialize EasyButton with the pin number
  40.  
  41. /****** CALLBACK FUNCTION *****/
  42. void onPressed()
  43. {
  44.   Serial.println("Button pressed");
  45. }
  46.  
  47. void setup(void)
  48. {
  49.   // put your setup code here, to run once:
  50.   Serial.begin(115200);  // Initialize serial communication
  51.   Serial.println();
  52.   Serial.println(">>> EasyButton pressed example <<<");
  53.  
  54.   button.begin();  // Initialize the button
  55.   button.onPressed(onPressed);  // Attach the callback function
  56. }
  57.  
  58. void loop(void)
  59. {
  60.   // put your main code here, to run repeatedly:
  61.   button.read();  // Read the button state
  62. }
  63.  
  64. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement