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-08-27 09:57:23
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* when pressin button1 led1 turns on and off whith */
- /* each press. while led1 is on i can press button2 */
- /* to turn led off while pressing the button2 but if */
- /* i release button2 the led1 turns on again */
- /****** 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 button1_PushButton_PIN_D2 = 2;
- const uint8_t Button2_PushButton_PIN_D3 = 3;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t LED1_LED_PIN_D4 = 4;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool LED1_LED_PIN_D4_rawData = false; // Initialize LED state to off
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Initialize EasyButton objects for both buttons
- EasyButton button1(button1_PushButton_PIN_D2); // Create an EasyButton object for button 1
- EasyButton button2(Button2_PushButton_PIN_D3); // Create an EasyButton object for button 2
- void setup(void)
- {
- // Initialize serial communication for debugging
- Serial.begin(115200);
- // Initialize button pins with internal pull-up resistors
- pinMode(button1_PushButton_PIN_D2, INPUT_PULLUP);
- pinMode(Button2_PushButton_PIN_D3, INPUT_PULLUP);
- // Initialize LED pin as output
- pinMode(LED1_LED_PIN_D4, OUTPUT);
- // Begin the EasyButton instances
- button1.begin(); // Initialize button 1
- button2.begin(); // Initialize button 2
- // Attach functions to button press events
- button1.onPressed([]() {
- Serial.println("Button 1 pressed");
- LED1_LED_PIN_D4_rawData = !LED1_LED_PIN_D4_rawData; // Toggle LED state
- });
- button2.onPressed([]() {
- Serial.println("Button 2 pressed");
- // Turn off LED while button 2 is pressed
- LED1_LED_PIN_D4_rawData = false;
- });
- }
- void loop(void)
- {
- // Read the button states
- button1.read(); // Read button 1 state
- button2.read(); // Read button 2 state
- // If button 2 is released, turn LED back on if it was previously on
- if (button2.isReleased() && LED1_LED_PIN_D4_rawData) {
- LED1_LED_PIN_D4_rawData = true; // Keep LED on
- }
- // Refresh output data
- updateOutputs();
- }
- void updateOutputs()
- {
- digitalWrite(LED1_LED_PIN_D4, LED1_LED_PIN_D4_rawData); // Update LED state based on raw data
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement