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-09-21 16:27:45
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Implement a push button interface using the */
- /* EasyButton library, ensuring reliable button state */
- /* detection with INPUT_PULLUP configuration on pin */
- /* D2 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 gfg_PushButton_PIN_D2 = 2;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Initialize the EasyButton object with the defined button pin
- EasyButton button(gfg_PushButton_PIN_D2); // Create an instance of EasyButton
- // Function to be called when the button is pressed
- void onPressed()
- {
- Serial.println("Button pressed"); // Print message to Serial Monitor
- }
- void setup(void)
- {
- // Start the Serial communication
- Serial.begin(115200);
- Serial.println();
- Serial.println(">>> EasyButton pressed example <<<");
- // Set the button pin as input with pull-up resistor
- pinMode(gfg_PushButton_PIN_D2, INPUT_PULLUP); // Configure pin D2 with INPUT_PULLUP
- // Initialize the EasyButton instance
- button.begin();
- // Attach the onPressed function to the button press event
- button.onPressed(onPressed);
- }
- void loop(void)
- {
- // Read the button state
- button.read(); // Check the button state and call the appropriate function
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement