Advertisement
pleasedontcode

ESC Control rev_04

Oct 19th, 2024
79
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: ESC Control
  13.     - Source Code NOT compiled for: Arduino Nano
  14.     - Source Code created on: 2024-10-19 13:55:46
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* code to control two escs connected to specify */
  21.     /* pins, start with calibration and arming for 30s */
  22.     /* then run the motors for 45s with 50% of speed */
  23.     /* after that turn off the motors */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <Servo.h>  //https://github.com/arduino-libraries/Servo
  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 esc1_PIN_D6       = 6; // Pin for ESC1
  36. const uint8_t esc2_PIN_D9       = 9; // Pin for ESC2
  37.  
  38. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  39. /***** used to store raw data *****/
  40. uint8_t esc1_PIN_D6_rawData     = 0;
  41. uint8_t esc2_PIN_D9_rawData     = 0;
  42.  
  43. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  44. // Create Servo objects for each ESC
  45. Servo esc1; // Object for ESC1
  46. Servo esc2; // Object for ESC2
  47.  
  48. void setup(void)
  49. {
  50.     // Attach the Servo objects to the corresponding pins
  51.     esc1.attach(esc1_PIN_D6); // Attach ESC1 to pin D6
  52.     esc2.attach(esc2_PIN_D9); // Attach ESC2 to pin D9
  53.  
  54.     // Initialize ESCs for calibration and arming
  55.     for (int i = 0; i < 30; i++) { // 30 seconds for calibration
  56.         esc1.write(0); // Send minimum signal to ESC1
  57.         esc2.write(0); // Send minimum signal to ESC2
  58.         delay(1000); // Wait for 1 second
  59.     }
  60.  
  61.     // After calibration, send a signal to arm the ESCs
  62.     esc1.write(90); // Send a neutral signal to ESC1
  63.     esc2.write(90); // Send a neutral signal to ESC2
  64.     delay(2000); // Wait for 2 seconds to ensure ESCs are armed
  65.  
  66.     // Run the motors at 50% speed for 45 seconds
  67.     for (int i = 0; i < 45; i++) { // 45 seconds
  68.         esc1.write(127); // Set ESC1 to 50% speed
  69.         esc2.write(127); // Set ESC2 to 50% speed
  70.         delay(1000); // Wait for 1 second
  71.     }
  72.  
  73.     // Turn off the motors
  74.     esc1.write(0); // Send minimum signal to ESC1
  75.     esc2.write(0); // Send minimum signal to ESC2
  76. }
  77.  
  78. void loop(void)
  79. {
  80.     // The loop function is empty as all actions are handled in setup
  81. }
  82.  
  83. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement