/********* 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 LED" - Source Code NOT compiled for: Arduino Uno - Source Code created on: 2024-06-21 14:40:29 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Develop an Arduino project using the EasyButton */ /* library to control an LED connected to pin D3. The */ /* LED should toggle its state each time a push */ /* button connected to pin D2 is pressed. Ensure the */ /* system initializes correctly in the setup */ /* function. */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include //https://github.com/evert-arias/EasyButton /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void onPressed(void); void updateOutputs(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t Botao_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*****/ EasyButton button(Botao_PushButton_PIN_D2); // Initialize EasyButton object void setup(void) { // put your setup code here, to run once: pinMode(Botao_PushButton_PIN_D2, INPUT_PULLUP); // Set button pin as input with internal pull-up pinMode(Led_LED_PIN_D3, OUTPUT); // Set LED pin as output Serial.begin(115200); // Initialize serial communication Serial.println(); Serial.println(">>> EasyButton pressed example <<<"); button.begin(); // Initialize the button button.onPressed(onPressed); // Set the callback function for button press } void loop(void) { // put your main code here, to run repeatedly: button.read(); // Continuously read the status of the button updateOutputs(); // Refresh output data } void onPressed() { Serial.println("Button pressed"); Led_LED_PIN_D3_rawData = !Led_LED_PIN_D3_rawData; // Toggle LED state } void updateOutputs() { digitalWrite(Led_LED_PIN_D3, Led_LED_PIN_D3_rawData); // Update the LED state } /* END CODE */