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
- - Version: 002
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2026-03-09 18:47:55
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* When Button1 is pressed, turn on LED1. When */
- /* Button1 is released, turn off LED1. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void onButton1Pressed(void);
- void onButton1Released(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- // Button1 is connected to GPIO pin 0 (A0 equivalent on ESP32)
- const uint8_t Button1_PushButton_PIN_A0 = 0;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- // LED1 is connected to GPIO pin 1 (A1 equivalent on ESP32)
- const uint8_t LED1_LED_PIN_A1 = 1;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create EasyButton instance for Button1
- EasyButton button1(Button1_PushButton_PIN_A0);
- /****** SYSTEM REQUIREMENT 1 *****/
- /* When Button1 is pressed, turn on LED1. When */
- /* Button1 is released, turn off LED1. */
- // Callback function to handle Button1 press event
- void onButton1Pressed(void)
- {
- // Turn on LED1 when button is pressed
- digitalWrite(LED1_LED_PIN_A1, HIGH);
- }
- // Callback function to handle Button1 release event
- void onButton1Released(void)
- {
- // Turn off LED1 when button is released
- digitalWrite(LED1_LED_PIN_A1, LOW);
- }
- void setup(void)
- {
- // put your setup code here, to run once:
- // Configure Button1 pin as input with pull-up resistor
- pinMode(Button1_PushButton_PIN_A0, INPUT_PULLUP);
- // Configure LED1 pin as output
- pinMode(LED1_LED_PIN_A1, OUTPUT);
- // Initialize button1 with default settings
- button1.begin();
- // Attach callback functions to button events
- button1.onPressed(onButton1Pressed);
- button1.onReleased(onButton1Released);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- // Read button state to update internal state machine
- button1.read();
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment