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: EasyButton LED
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-05-12 13:23:36
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Turns on and off a light emitting diode(LED), when */
- /* pressing a digital button through api calls */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t LED_PIN_D4 = 4;
- const uint8_t BUTTON_PIN = 2; // Assuming the button is connected to pin 2
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- bool LED_PIN_D4_rawData = false;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float LED_PIN_D4_phyData = 0.0;
- // Define the EasyButton object for the button
- EasyButton button(BUTTON_PIN);
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(LED_PIN_D4, OUTPUT);
- // Initialize the button
- button.begin();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- button.update(); // Update the button state
- // Check if the button is pressed
- if (button.read())
- {
- // Toggle the LED state
- LED_PIN_D4_rawData = !LED_PIN_D4_rawData;
- updateOutputs(); // Update the LED state
- }
- }
- void updateOutputs(void)
- {
- digitalWrite(LED_PIN_D4, LED_PIN_D4_rawData);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement