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: LED Control
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-10-29 10:29:04
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* when push button turn on else turn off */
- /****** 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 pushbutonled_PushButton_PIN_D4 = 4; // Pin for the push button
- const uint8_t led_PIN = 13; // Pin for the LED (change as needed)
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Initialize the EasyButton object with the defined pin.
- // The default debounce time and pullup settings will be used.
- EasyButton button(pushbutonled_PushButton_PIN_D4);
- void onPressed()
- {
- Serial.println("Button pressed"); // Callback function to be called when the button is pressed.
- digitalWrite(led_PIN, HIGH); // Turn on the LED when the button is pressed.
- }
- void onReleased()
- {
- Serial.println("Button released"); // Callback function to be called when the button is released.
- digitalWrite(led_PIN, LOW); // Turn off the LED when the button is released.
- }
- void setup(void)
- {
- // Initialize Serial for debugging purposes.
- Serial.begin(115200);
- Serial.println();
- Serial.println(">>> EasyButton pressed example <<<");
- // Set the LED pin as OUTPUT.
- pinMode(led_PIN, OUTPUT);
- // Initialize the button.
- button.begin();
- // Add the callback functions to be called when the button is pressed and released.
- button.onPressed(onPressed);
- button.onReleased(onReleased);
- }
- void loop(void)
- {
- // Continuously read the status of the button.
- button.read();
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement