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 Toggle
- - Version: 001
- - Source Code NOT compiled for: Arduino UNO Q
- - Source Code created on: 2026-03-03 16:03:14
- ********* 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 *****/
- const uint8_t Button1_PushButton_PIN_A0 = A0;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t LED1_LED_PIN_A1 = A1;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create an instance of EasyButton for Button1
- // Parameters: pin number, debounce time (ms), enable pull-up, active low
- EasyButton button1(Button1_PushButton_PIN_A0, 35, true, true);
- // Callback function triggered when Button1 is pressed
- void onButton1Pressed(void)
- {
- // Turn on LED1 when button is pressed
- digitalWrite(LED1_LED_PIN_A1, HIGH);
- }
- // Callback function triggered when Button1 is released
- void onButton1Released(void)
- {
- // Turn off LED1 when button is released
- digitalWrite(LED1_LED_PIN_A1, LOW);
- }
- void setup(void)
- {
- // Configure Button1 as input with pull-up
- pinMode(Button1_PushButton_PIN_A0, INPUT_PULLUP);
- // Configure LED1 as output
- pinMode(LED1_LED_PIN_A1, OUTPUT);
- // Ensure LED1 is off at startup
- digitalWrite(LED1_LED_PIN_A1, LOW);
- // Initialize the EasyButton instance
- button1.begin();
- // Register callback function for when button is pressed
- button1.onPressed(onButton1Pressed);
- // Register callback function for when button is released
- button1.onReleased(onButton1Released);
- }
- void loop(void)
- {
- // Continuously read the button status to detect press and release events
- button1.read();
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment