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: Servo Control
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-10-08 05:50:18
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The system shall utilize the Deneyap Servo library */
- /* to control servo motors based on push button */
- /* inputs from digital pin D2, ensuring responsive */
- /* and accurate motor movements. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Deneyap_Servo.h> //https://github.com/deneyapkart/deneyap-servo-arduino-library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t mybutton_PushButton_PIN_D2 = 2; // Define push button pin
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Instantiate the Servo class for controlling a servo motor
- Servo myservo; // Create an instance of the Servo class
- void setup(void)
- {
- // Set the button pin as input with pull-up resistor
- pinMode(mybutton_PushButton_PIN_D2, INPUT_PULLUP);
- // Attach the servo to pin D9 (default channel 0, freq 50, resolution 12)
- myservo.attach(D9);
- }
- void loop(void)
- {
- // Check if the button is pressed
- if (digitalRead(mybutton_PushButton_PIN_D2) == LOW) { // Button pressed (active low)
- myservo.write(60); // Move the servo to 60 degrees
- delay(1000); // Wait for a second
- myservo.write(0); // Move the servo back to 0 degrees
- delay(1000); // Wait for a second
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement