Advertisement
pleasedontcode

ESC Control rev_03

Oct 19th, 2024
59
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:47:26
  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 <ESC.h>    // https://github.com/RB-ENantel/RC_ESC
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32.  
  33. /***** DEFINITION OF PWM OUTPUT PINS *****/
  34. const uint8_t esc1_PIN_D6 = 6; // Pin for ESC1
  35. const uint8_t esc2_PIN_D9 = 9; // Pin for ESC2
  36.  
  37. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  38. /***** used to store raw data *****/
  39. uint8_t esc1_PIN_D6_rawData = 0;
  40. uint8_t esc2_PIN_D9_rawData = 0;
  41.  
  42. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  43. /***** used to store data after characteristic curve transformation *****/
  44. float esc1_PIN_D6_phyData = 0.0;
  45. float esc2_PIN_D9_phyData = 0.0;
  46.  
  47. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  48. ESC esc1(esc1_PIN_D6, 1000, 2000, 500);  // Instance for ESC1 on pin D6
  49. ESC esc2(esc2_PIN_D9, 1000, 2000, 500);  // Instance for ESC2 on pin D9
  50.  
  51. void setup(void)
  52. {
  53.     // Initialize PWM output pins
  54.     pinMode(esc1_PIN_D6, OUTPUT);
  55.     pinMode(esc2_PIN_D9, OUTPUT);
  56.  
  57.     // Calibrate ESCs
  58.     esc1.calib();
  59.     esc2.calib();
  60.  
  61.     // Stop ESCs after calibration
  62.     esc1.stop();
  63.     esc2.stop();
  64.  
  65.     // Arm ESCs for 30 seconds
  66.     esc1.arm();
  67.     esc2.arm();
  68.     delay(30000); // Wait for 30 seconds
  69. }
  70.  
  71. void loop(void)
  72. {
  73.     // Set speed to 50% for 45 seconds
  74.     esc1.speed(1500); // 50% speed for ESC1
  75.     esc2.speed(1500); // 50% speed for ESC2
  76.     delay(45000); // Wait for 45 seconds
  77.  
  78.     // Turn off motors
  79.     esc1.stop();
  80.     esc2.stop();
  81.  
  82.     // Stop loop execution
  83.     while (true); // Stop further execution
  84. }
  85.  
  86. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement