Advertisement
pleasedontcode

Servo Control rev_02

Oct 19th, 2024
60
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:44:26
  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. /****** SYSTEM REQUIREMENT 2 *****/
  24.     /* two escs connected to specify pins, start with */
  25.     /* arming motors and wait 15s with throttles in */
  26.     /* minimum positions, then start motors with 25% */
  27.     /* speed for 45s a then turn off the motors */
  28. /****** END SYSTEM REQUIREMENTS *****/
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include <Servo.h>  // https://github.com/arduino-libraries/Servo
  32. #include <ESC.h>    // https://github.com/RB-ENantel/RC_ESC
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. /***** DEFINITION OF PWM OUTPUT PINS *****/
  39. const uint8_t motor_Servomotor_PWMSignal_PIN_D3     = 3; // Pin for first servo
  40. const uint8_t motor2_Servomotor_PWMSignal_PIN_D5        = 5; // Pin for second servo
  41.  
  42. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  43. Servo myServo1; // Instance of Servo class for motor on pin D3
  44. Servo myServo2; // Instance of Servo class for motor on pin D5
  45. ESC myESC1(9, 1000, 2000, 500); // Instance of ESC class for first ESC
  46. ESC myESC2(10, 1000, 2000, 500); // Instance of ESC class for second ESC
  47.  
  48. void setup(void)
  49. {
  50.     // Set the PWM pins as outputs
  51.     pinMode(motor_Servomotor_PWMSignal_PIN_D3, OUTPUT);
  52.     pinMode(motor2_Servomotor_PWMSignal_PIN_D5, OUTPUT);
  53.  
  54.     // Attach the servos to their respective pins
  55.     myServo1.attach(motor_Servomotor_PWMSignal_PIN_D3);
  56.     myServo2.attach(motor2_Servomotor_PWMSignal_PIN_D5);
  57.  
  58.     // Start ESC calibration for both ESCs
  59.     myESC1.calib();
  60.     myESC2.calib();
  61.  
  62.     // Wait for 15 seconds with minimum throttle for ESCs
  63.     delay(15000);
  64.  
  65.     // Start motors at 25% power for 45 seconds
  66.     myESC1.write(64); // 25% throttle for first ESC
  67.     myESC2.write(64); // 25% throttle for second ESC
  68.     delay(45000); // Run at 25% power for 45 seconds
  69.  
  70.     // Stop the motors
  71.     myESC1.stop();
  72.     myESC2.stop();
  73. }
  74.  
  75. void loop(void)
  76. {
  77.     // Main loop does not need to perform any actions
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement