/********* 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: "Servo Control" - Source Code compiled for: Arduino Uno - Source Code created on: 2024-01-02 08:01:45 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* To control servo motor angle */ /****** SYSTEM REQUIREMENT 2 *****/ /* To control servo motor angle */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include #include #include /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* To control servo motor angle */ /****** SYSTEM REQUIREMENT 2 *****/ /* To control servo motor angle */ /****** END SYSTEM REQUIREMENTS *****/ /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t Servomotor_PushButton_PIN_D2 = 2; const uint8_t ServoMotor_PIN = 9; // Replace with the actual pin number for the servo motor /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/ EasyButton button(Servomotor_PushButton_PIN_D2); Servo servo; void setup(void) { // put your setup code here, to run once: pinMode(Servomotor_PushButton_PIN_D2, INPUT_PULLUP); servo.attach(ServoMotor_PIN); servo.write(90); // Set the servo to the initial angle of 90 degrees } void loop(void) { // put your main code here, to run repeatedly: button.update(); if (button.isPressed()) { // Perform actions when the button is pressed int currentAngle = servo.read(); if (currentAngle == 90) { servo.write(180); // Rotate the servo to 180 degrees } else { servo.write(90); // Rotate the servo back to 90 degrees } delay(500); // Delay to avoid multiple button presses } }