Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "Button Detection"
- - Source Code compiled for: Arduino Mega
- - Source Code created on: 2024-07-11 23:13:31
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* read button */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void onPressed(void); // Prototype for the button press callback function
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t button_PushButton_PIN_D2 = 2;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- EasyButton button(button_PushButton_PIN_D2); // Initialize EasyButton object
- /****** CALLBACK FUNCTION FOR BUTTON PRESS *****/
- void onPressed()
- {
- Serial.println("Button pressed");
- }
- void setup(void)
- {
- // Initialize serial communication
- Serial.begin(115200);
- Serial.println();
- Serial.println(">>> EasyButton pressed example <<<");
- // Initialize button
- button.begin();
- button.onPressed(onPressed); // Attach the callback function
- // Set pin mode
- pinMode(button_PushButton_PIN_D2, INPUT_PULLUP);
- }
- void loop(void)
- {
- // Read the button state
- button.read(); // read button
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement