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:09:13
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* 舵机旋转360度 每转10度led 12脚亮0.5秒 循环 禁用延迟 */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Deneyap_Servo.h> //https://github.com/deneyapkart/deneyap-servo-arduino-library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- void rotateServo();
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t AA_Servomotor_PWMSignal_PIN_D4 = 4;
- const uint8_t LED_PIN = 12; // Define LED pin
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- uint8_t AA_Servomotor_PWMSignal_PIN_D4_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float AA_Servomotor_PWMSignal_PIN_D4_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- Servo myServo; // Create an instance of the Servo class
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(LED_PIN, OUTPUT); // Set LED pin as output
- myServo.attach(AA_Servomotor_PWMSignal_PIN_D4); // Attach the servo to the PWM pin
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- rotateServo(); // Rotate the servo
- }
- void updateOutputs()
- {
- analogWrite(AA_Servomotor_PWMSignal_PIN_D4, AA_Servomotor_PWMSignal_PIN_D4_rawData);
- }
- void rotateServo()
- {
- for (int angle = 0; angle <= 360; angle += 10) {
- myServo.write(angle); // Rotate servo to the specified angle
- digitalWrite(LED_PIN, HIGH); // Turn on LED
- delay(500); // Wait for 0.5 seconds
- digitalWrite(LED_PIN, LOW); // Turn off LED
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement