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: ESP32 DevKit V1
- - Source Code created on: 2025-01-26 13:07:37
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* 舵机旋转360度 每转10度led 12脚亮0.5秒 循环 禁用延迟 */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Servo.h> // Include the Servo library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /****** GLOBAL VARIABLES *****/
- Servo myServo; // Create a Servo object
- const int ledPin = 12; // Define LED pin
- const int servoPin = 9; // Define Servo pin
- int angle = 0; // Initial angle
- void setup(void)
- {
- // Initialize the servo and LED
- myServo.attach(servoPin); // Attach the servo to the pin
- pinMode(ledPin, OUTPUT); // Set LED pin as output
- }
- void loop(void)
- {
- // Rotate the servo from 0 to 360 degrees in steps of 10 degrees
- for (angle = 0; angle <= 360; angle += 10)
- {
- myServo.write(angle); // Move the servo to the specified angle
- digitalWrite(ledPin, HIGH); // Turn on the LED
- delay(500); // Keep the LED on for 0.5 seconds
- digitalWrite(ledPin, LOW); // Turn off the LED
- }
- // After reaching 360 degrees, reset the angle to 0
- angle = 0;
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement