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 NOT compiled for: Arduino Uno
- - Source Code created on: 2024-08-30 11:25:51
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Implement a button press detection system using */
- /* the EasyButton library to monitor the state of a */
- /* push button connected to digital pin D2, ensuring */
- /* reliable input handling for user interactions. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t rtc_PushButton_PIN_D2 = 2; // Define the pin for the push button
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Initialize the EasyButton object with the defined button pin
- EasyButton button(rtc_PushButton_PIN_D2);
- /****** FUNCTION DEFINITIONS *****/
- void onPressed()
- {
- Serial.println("Button pressed"); // Function to execute when the button is pressed
- }
- void setup(void)
- {
- // Initialize serial communication for debugging
- Serial.begin(115200);
- Serial.println();
- Serial.println(">>> EasyButton pressed example <<<");
- // Set the button pin mode
- pinMode(rtc_PushButton_PIN_D2, INPUT_PULLUP); // Configure the button pin as input with pull-up resistor
- // Initialize the EasyButton
- button.begin();
- button.onPressed(onPressed); // Attach the onPressed function to the button event
- }
- void loop(void)
- {
- // Continuously read the button state
- button.read(); // This checks the button state and triggers the onPressed function if pressed
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement