Advertisement
pleasedontcode

Servo Control rev_01

Oct 19th, 2024
96
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 Nano
  14.     - Source Code created on: 2024-10-19 12:08:44
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* start servos with throttles minimum for 10s, then */
  21.     /* start at 25% power for 45s and after that turn off */
  22.     /* servos */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Servo.h>  //https://github.com/arduino-libraries/Servo
  27. #include <ESC.h>    //https://github.com/RB-ENantel/RC_ESC
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void updateOutputs(void);
  33.  
  34. /***** DEFINITION OF PWM OUTPUT PINS *****/
  35. const uint8_t motor_Servomotor_PWMSignal_PIN_D3     = 3;
  36. const uint8_t motor2_Servomotor_PWMSignal_PIN_D5        = 5;
  37.  
  38. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  39. /***** used to store raw data *****/
  40. uint8_t motor_Servomotor_PWMSignal_PIN_D3_rawData       = 0; // Minimum throttle
  41. uint8_t motor2_Servomotor_PWMSignal_PIN_D5_rawData      = 0; // Minimum throttle
  42.  
  43. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  44. // Create Servo objects for each motor
  45. Servo motorServo1; // Servo object for motor on pin D3
  46. Servo motorServo2; // Servo object for motor on pin D5
  47.  
  48. void setup(void)
  49. {
  50.     // Attach the Servo objects to the corresponding PWM pins
  51.     motorServo1.attach(motor_Servomotor_PWMSignal_PIN_D3);
  52.     motorServo2.attach(motor2_Servomotor_PWMSignal_PIN_D5);
  53.    
  54.     // Start servos with minimum throttle
  55.     motor_Servomotor_PWMSignal_PIN_D3_rawData = 0; // Minimum throttle
  56.     motor2_Servomotor_PWMSignal_PIN_D5_rawData = 0; // Minimum throttle
  57.     updateOutputs(); // Write minimum throttle to servos
  58.     delay(10000); // Wait for 10 seconds
  59.  
  60.     // Start at 25% power (assuming 0-180 degrees, 25% is 45 degrees)
  61.     motor_Servomotor_PWMSignal_PIN_D3_rawData = 45; // 25% power
  62.     motor2_Servomotor_PWMSignal_PIN_D5_rawData = 45; // 25% power
  63.     updateOutputs(); // Write 25% power to servos
  64.     delay(45000); // Wait for 45 seconds
  65.  
  66.     // Turn off servos
  67.     motor_Servomotor_PWMSignal_PIN_D3_rawData = 0; // Minimum throttle
  68.     motor2_Servomotor_PWMSignal_PIN_D5_rawData = 0; // Minimum throttle
  69.     updateOutputs(); // Write minimum throttle to servos
  70. }
  71.  
  72. void loop(void)
  73. {
  74.     // No need to do anything in loop since all actions are in setup
  75. }
  76.  
  77. void updateOutputs()
  78. {
  79.     // Write the raw data to the Servo objects
  80.     motorServo1.write(motor_Servomotor_PWMSignal_PIN_D3_rawData);
  81.     motorServo2.write(motor2_Servomotor_PWMSignal_PIN_D5_rawData);
  82. }
  83.  
  84. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement