Advertisement
pleasedontcode

Button Hello rev_01

Jan 24th, 2024
99
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 Hello
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-24 20:30:24
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* if button is pressed so print hello on serial */
  21.     /* monitor */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <EasyButton.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup();
  29. void loop();
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t buttonPin = 2;
  33.  
  34. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  35. EasyButton button(buttonPin);  // Instantiate the EasyButton object with the button pin
  36.  
  37. void setup() {
  38.   pinMode(buttonPin, INPUT_PULLUP);  // Set the button pin as INPUT_PULLUP
  39.  
  40.   button.begin();  // Initialize the button object
  41.  
  42.   // Define the callback function for when the button is pressed
  43.   button.onPressed([]() {
  44.     Serial.println("Hello");
  45.   });
  46.  
  47.   // Start the serial communication
  48.   Serial.begin(115200);
  49.   Serial.println();
  50.   Serial.println(">>> EasyButton pressed example <<<");
  51. }
  52.  
  53. void loop() {
  54.   button.read();  // Read the button state
  55.  
  56.   // Add your additional code here
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement