Advertisement
pleasedontcode

Button Action rev_01

Mar 25th, 2024
125
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 Action
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-25 21:57:48
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* proekt ti rekovmi rece */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <EasyButton.h>  // Library for reading button input
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29. void handleButtonPress(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t butt_PushButton_PIN_D2 = 2;
  33.  
  34. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  35. EasyButton button(butt_PushButton_PIN_D2);
  36.  
  37. void setup(void)
  38. {
  39.   // Initialize serial communication
  40.   Serial.begin(115200);
  41.   Serial.println();
  42.   Serial.println(">>> LUA DTO Example <<<");
  43.  
  44.   // Setup pin mode
  45.   pinMode(butt_PushButton_PIN_D2, INPUT_PULLUP);
  46.  
  47.   // Initialize the button
  48.   button.begin();
  49.  
  50.   // Attach the handleButtonPress function to the button's pressed event
  51.   button.onPressed(handleButtonPress);
  52.  
  53. }
  54.  
  55. void loop(void)
  56. {
  57.   // Continuously check the button state
  58.   button.read();
  59.   delay(50); // Add a small delay to avoid button jitters or multiple triggers
  60.  
  61. }
  62.  
  63. void handleButtonPress(void)
  64. {
  65.   // Perform action based on the button pressed
  66.   Serial.println("Button pressed");
  67.  
  68.   // Call other functions or update sensor values here based on the button press
  69.  
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement