/********* 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 Control - Source Code compiled for: Arduino Nano - Source Code created on: 2024-03-30 19:54:51 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* servo go 90 degres if button is presed? led on */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include // Servo library for controlling servo motors #include // EasyButton library for handling button inputs /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void onPressed(); /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* servo go 90 degrees if button is pressed? led on */ /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t button_PIN_D2 = 2; /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t led_PIN_D4 = 4; /***** DEFINITION OF PWM OUTPUT PINS *****/ const uint8_t servo_PIN_D3 = 3; /***** DEFINITION OF OUTPUT RAW VARIABLES *****/ bool led_rawData = false; uint8_t servo_rawData = 0; /***** DEFINITION OF LIBRARIES CLASS INSTANCES *****/ Servo myservo; // Servo object for controlling the servo motor EasyButton button(button_PIN_D2); // EasyButton object for handling button input void setup() { pinMode(led_PIN_D4, OUTPUT); // Set LED pin as output myservo.attach(servo_PIN_D3); // Attach servo motor to PWM pin button.begin(); // Initialize the button object button.onPressed(onPressed); // Set onPressed function as callback for button press event } void loop() { button.read(); // Read the button state if (button.isPressed()) { led_rawData = true; myservo.write(90); // Set servo angle to 90 degrees } else { led_rawData = false; } digitalWrite(led_PIN_D4, led_rawData); // Set LED state based on led_rawData value } void onPressed() { // Button pressed event }