Advertisement
pleasedontcode

Button Setup rev_219

Jan 17th, 2024
69
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 Setup
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-18 01:02:52
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* if button pressed, so print hello */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <EasyButton.h>
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29.  
  30. /****** SYSTEM REQUIREMENTS *****/
  31. /****** SYSTEM REQUIREMENT 1 *****/
  32.     /* if button pressed, so print hello */
  33. /****** END SYSTEM REQUIREMENTS *****/
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t butt_PushButton_PIN_D2 = 2;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. EasyButton button(butt_PushButton_PIN_D2); // Object of EasyButton class
  40.  
  41. void setup(void)
  42. {
  43.     // Initialize Serial communication
  44.     Serial.begin(115200);
  45.     Serial.println();
  46.     Serial.println(">>> EasyButton pressed example <<<");
  47.  
  48.     // Set the push button pin as INPUT_PULLUP
  49.     pinMode(butt_PushButton_PIN_D2, INPUT_PULLUP);
  50.  
  51.     // Attach a callback function to be called when the button is pressed
  52.     button.onPressed([]() {
  53.         Serial.println("Hello");
  54.     }) ;
  55.  
  56.     // Initialize the button
  57.     button.begin();
  58. }
  59.  
  60. void loop(void)
  61. {
  62.     // Read the button state
  63.     bool buttonPressed = button.read();
  64.  
  65.     // Check if button is pressed
  66.     if(buttonPressed)
  67.     {
  68.         // Print "Hello"
  69.         Serial.println("Hello");
  70.        
  71.         // Add any additional actions based on the button press here
  72.     }
  73.  
  74.     // Delay to allow other operations
  75.     delay(10);
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement