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 Toggle
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-10-11 11:37:35
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The system shall detect button presses on a push */
- /* button connected to pin D2 and control an LED */
- /* connected to pin D3, using the EasyButton library */
- /* for efficient button handling and state */
- /* management. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void); // Function prototype for updating outputs
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Button_PushButton_PIN_D2 = 2;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t led_LED_PIN_D3 = 3;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool led_LED_PIN_D3_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float led_LED_PIN_D3_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Initialize the EasyButton object for the push button
- EasyButton button(Button_PushButton_PIN_D2);
- /****** FUNCTION DEFINITIONS *****/
- void setup(void)
- {
- // Set the button pin as input with pull-up resistor
- pinMode(Button_PushButton_PIN_D2, INPUT_PULLUP);
- // Set the LED pin as output
- pinMode(led_LED_PIN_D3, OUTPUT);
- // Initialize the button
- button.begin();
- // Attach the onPressed event to the button
- button.onPressed([]() {
- led_LED_PIN_D3_rawData = !led_LED_PIN_D3_rawData; // Toggle the LED state
- });
- }
- void loop(void)
- {
- // Read the button state
- button.read(); // Read the button state
- updateOutputs(); // Refresh output data
- }
- void updateOutputs()
- {
- // Write the LED state
- digitalWrite(led_LED_PIN_D3, led_LED_PIN_D3_rawData); // Write the LED state
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement