Advertisement
pleasedontcode

Servo Control rev_01

Oct 25th, 2024
68
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: Arduino Uno
  14.     - Source Code created on: 2024-10-25 06:55:51
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Turn servo with speed increased */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Servo.h>  //https://github.com/arduino-libraries/Servo
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29. void updateOutputs(void);
  30.  
  31. /***** DEFINITION OF PWM OUTPUT PINS *****/
  32. const uint8_t brusheless_Servomotor_PWMSignal_PIN_D3        = 3;
  33.  
  34. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  35. /***** used to store raw data *****/
  36. uint8_t brusheless_Servomotor_PWMSignal_PIN_D3_rawData      = 0;
  37.  
  38. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  39. /***** used to store data after characteristic curve transformation *****/
  40. float brusheless_Servomotor_PWMSignal_PIN_D3_phyData        = 0.0;
  41.  
  42. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  43. // Create an instance of the Servo class
  44. Servo myServo; // Initialize the Servo object
  45.  
  46. void setup(void)
  47. {
  48.     // put your setup code here, to run once:
  49.     pinMode(brusheless_Servomotor_PWMSignal_PIN_D3, OUTPUT); // Set the PWM pin as output
  50.  
  51.     myServo.attach(brusheless_Servomotor_PWMSignal_PIN_D3); // Attach the Servo object to the PWM pin
  52. }
  53.  
  54. void loop(void)
  55. {
  56.     // put your main code here, to run repeatedly:
  57.     updateOutputs(); // Refresh output data
  58. }
  59.  
  60. // Function to update outputs and control servo speed
  61. void updateOutputs()
  62. {
  63.     // Increase the speed of the servo by adjusting the position in smaller increments
  64.     for (brusheless_Servomotor_PWMSignal_PIN_D3_rawData = 0; brusheless_Servomotor_PWMSignal_PIN_D3_rawData <= 180; brusheless_Servomotor_PWMSignal_PIN_D3_rawData += 1) // Increment position by 1 degree for faster movement
  65.     {
  66.         myServo.write(brusheless_Servomotor_PWMSignal_PIN_D3_rawData); // Use the Servo object to set the position
  67.         delay(10); // Wait for the servo to reach the position (decreased delay for increased speed)
  68.     }
  69.     for (brusheless_Servomotor_PWMSignal_PIN_D3_rawData = 180; brusheless_Servomotor_PWMSignal_PIN_D3_rawData >= 0; brusheless_Servomotor_PWMSignal_PIN_D3_rawData -= 1) // Decrement position by 1 degree for faster movement
  70.     {
  71.         myServo.write(brusheless_Servomotor_PWMSignal_PIN_D3_rawData); // Use the Servo object to set the position
  72.         delay(10); // Wait for the servo to reach the position (decreased delay for increased speed)
  73.     }
  74. }
  75.  
  76. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement