/********* 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 Control - Source Code NOT compiled for: Arduino Uno - Source Code created on: 2024-10-02 08:44:36 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Arduino library for debouncing momentary contact */ /* switches, detect press, release, long press and */ /* sequences with event definitions and callbacks. */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include // https://github.com/evert-arias/EasyButton #include // Include EasyButtonBase library #include // Include EasyButtonTouch library #include // Include EasyButtonVirtual library #include // Include Sequence library /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t elkewk_PushButton_PIN_D2 = 2; const uint8_t elkewk_TouchButton_PIN_D3 = 3; // Example pin for touch button const uint8_t elkewk_VirtualButton_PIN_D4 = 4; // Example pin for virtual button /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ // Initialize EasyButton object for the defined pin EasyButton button1(elkewk_PushButton_PIN_D2); EasyButtonTouch touchButton(elkewk_TouchButton_PIN_D3); // Initialize EasyButtonTouch object EasyButtonVirtual virtualButton(button1.read(), true); // Initialize EasyButtonVirtual object // Initialize a Sequence object (example usage) Sequence buttonSequence(3, 1000); // Example for 3 sequences with a duration of 1000 ms /****** FUNCTION DEFINITIONS *****/ void onButton1Pressed() { Serial.println("Button1 pressed"); // Callback function for button press } void onTouchButtonPressed() { Serial.println("Touch button pressed"); // Callback function for touch button press } void onVirtualButtonPressed() { Serial.println("Virtual button pressed"); // Callback function for virtual button press } void setup(void) { // Start serial communication for debugging Serial.begin(115200); // Print a message to the serial monitor Serial.println(); Serial.println(">>> EasyButton example <<<"); // Initialize the buttons button1.begin(); touchButton.begin(); // Initialize touch button virtualButton.begin(); // Initialize virtual button button1.onPressed(onButton1Pressed); // Set the callback for button press touchButton.onPressed(onTouchButtonPressed); // Set the callback for touch button press virtualButton.onPressed(onVirtualButtonPressed); // Set the callback for virtual button press // Set the pin mode for the button (not necessary for EasyButton, but kept for reference) pinMode(elkewk_PushButton_PIN_D2, INPUT_PULLUP); pinMode(elkewk_TouchButton_PIN_D3, INPUT_PULLUP); // Set touch button pin mode pinMode(elkewk_VirtualButton_PIN_D4, INPUT_PULLUP); // Set virtual button pin mode } void loop(void) { // Read the button states button1.read(); // This checks the button state and triggers the callback if pressed touchButton._readPin(); // Read the touch button state virtualButton.read(); // Read the virtual button state } /* END CODE */