Advertisement
pleasedontcode

"Servo Control" rev_02

Jan 26th, 2025
106
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:09:13
  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 <Deneyap_Servo.h>  //https://github.com/deneyapkart/deneyap-servo-arduino-library
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31. void updateOutputs();
  32. void rotateServo();
  33.  
  34. /***** DEFINITION OF PWM OUTPUT PINS *****/
  35. const uint8_t AA_Servomotor_PWMSignal_PIN_D4        = 4;
  36. const uint8_t LED_PIN = 12; // Define LED pin
  37.  
  38. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  39. uint8_t AA_Servomotor_PWMSignal_PIN_D4_rawData      = 0;
  40.  
  41. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  42. float   AA_Servomotor_PWMSignal_PIN_D4_phyData      = 0.0;
  43.  
  44. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  45. Servo myServo; // Create an instance of the Servo class
  46.  
  47. void setup(void)
  48. {
  49.     // put your setup code here, to run once:
  50.     pinMode(LED_PIN, OUTPUT); // Set LED pin as output
  51.     myServo.attach(AA_Servomotor_PWMSignal_PIN_D4); // Attach the servo to the PWM pin
  52. }
  53.  
  54. void loop(void)
  55. {
  56.     // put your main code here, to run repeatedly:
  57.     rotateServo(); // Rotate the servo
  58. }
  59.  
  60. void updateOutputs()
  61. {
  62.     analogWrite(AA_Servomotor_PWMSignal_PIN_D4, AA_Servomotor_PWMSignal_PIN_D4_rawData);
  63. }
  64.  
  65. void rotateServo()
  66. {
  67.     for (int angle = 0; angle <= 360; angle += 10) {
  68.         myServo.write(angle); // Rotate servo to the specified angle
  69.         digitalWrite(LED_PIN, HIGH); // Turn on LED
  70.         delay(500); // Wait for 0.5 seconds
  71.         digitalWrite(LED_PIN, LOW); // Turn off LED
  72.     }
  73. }
  74.  
  75. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement