Advertisement
pleasedontcode

**Servo Control** rev_01

Jan 26th, 2025
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **Servo Control**
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-01-26 13:07:37
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* 舵机旋转360度 每转10度led 12脚亮0.5秒 循环 禁用延迟 */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /* START CODE */
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Servo.h> // Include the Servo library
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /****** GLOBAL VARIABLES *****/
  33. Servo myServo; // Create a Servo object
  34. const int ledPin = 12; // Define LED pin
  35. const int servoPin = 9; // Define Servo pin
  36. int angle = 0; // Initial angle
  37.  
  38. void setup(void)
  39. {
  40.     // Initialize the servo and LED
  41.     myServo.attach(servoPin); // Attach the servo to the pin
  42.     pinMode(ledPin, OUTPUT); // Set LED pin as output
  43. }
  44.  
  45. void loop(void)
  46. {
  47.     // Rotate the servo from 0 to 360 degrees in steps of 10 degrees
  48.     for (angle = 0; angle <= 360; angle += 10)
  49.     {
  50.         myServo.write(angle); // Move the servo to the specified angle
  51.         digitalWrite(ledPin, HIGH); // Turn on the LED
  52.         delay(500); // Keep the LED on for 0.5 seconds
  53.         digitalWrite(ledPin, LOW); // Turn off the LED
  54.     }
  55.    
  56.     // After reaching 360 degrees, reset the angle to 0
  57.     angle = 0;
  58. }
  59.  
  60. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement