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 Callback"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-07-07 22:32:13
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Implement a system to detect button presses using */
- /* the EasyButton library. The system should */
- /* initialize a push button connected to pin D2 and */
- /* continuously monitor its state, triggering */
- /* specific actions upon button press events. */
- /****** 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); // Callback function prototype
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t left_PushButton_PIN_D2 = 2;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- EasyButton button(left_PushButton_PIN_D2); // Initialize EasyButton object
- void onPressed()
- {
- Serial.println("Button pressed"); // Callback function definition
- }
- void setup(void)
- {
- // put your setup code here, to run once:
- Serial.begin(115200); // Initialize Serial for debugging
- Serial.println();
- Serial.println(">>> EasyButton pressed example <<<");
- button.begin(); // Initialize the button
- button.onPressed(onPressed); // Set the callback function for button press
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- button.read(); // Continuously read the status of the button
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement