Advertisement
pleasedontcode

PWM Control rev_01

Sep 19th, 2024
99
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: PWM Control
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-09-19 15:28:31
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* a servo for steering and TB6612FNG motor driver */
  21.     /* for driving a motor. im using esp32 c3 as */
  22.     /* receiver. code so that proper pwm channel from */
  23.     /* esp32 c3 is used for pwm input for motor driver */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <Deneyap_Servo.h>  // Include the Deneyap Servo library
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void updateOutputs(void); // Function prototype for updating outputs
  33.  
  34. /***** DEFINITION OF PWM OUTPUT PINS *****/
  35. const uint8_t steeringServo_Servomotor_PWMSignal_PIN_D4 = 4; // Define the pin for the steering servo
  36. const uint8_t motorDriver_PWM_PIN_D5 = 5; // Define the pin for the motor driver PWM signal
  37.  
  38. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  39. /***** used to store raw data *****/
  40. uint8_t steeringServo_Servomotor_PWMSignal_PIN_D4_rawData = 0; // Variable to hold raw data for the servo
  41. uint8_t motorDriver_PWM_rawData = 0; // Variable to hold raw data for the motor driver
  42.  
  43. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  44. /***** used to store data after characteristic curve transformation *****/
  45. float steeringServo_Servomotor_PWMSignal_PIN_D4_phyData = 0.0; // Variable to hold transformed data for the servo
  46. float motorDriver_PWM_phyData = 0.0; // Variable to hold transformed data for the motor driver
  47.  
  48. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  49. // Create an instance of the Servo class for the steering servo
  50. Servo steeringServo; // Initialize the servo object
  51.  
  52. void setup(void)
  53. {
  54.     // Attach the servo to the defined pin and set the PWM properties
  55.     steeringServo.attach(steeringServo_Servomotor_PWMSignal_PIN_D4); // Attach the servo to the defined pin
  56.     pinMode(steeringServo_Servomotor_PWMSignal_PIN_D4, OUTPUT); // Set the pin mode to OUTPUT
  57.     pinMode(motorDriver_PWM_PIN_D5, OUTPUT); // Set the motor driver pin mode to OUTPUT
  58. }
  59.  
  60. void loop(void)
  61. {
  62.     // Refresh output data
  63.     updateOutputs(); // Call function to update servo position
  64. }
  65.  
  66. void updateOutputs()
  67. {
  68.     // Write the raw data to the servo
  69.     steeringServo.write(steeringServo_Servomotor_PWMSignal_PIN_D4_rawData); // Write the raw data to the servo
  70.  
  71.     // Write the raw data to the motor driver (if applicable)
  72.     // Assuming motorDriver_PWM_rawData is set somewhere in the code
  73.     // analogWrite(motorDriver_PWM_PIN_D5, motorDriver_PWM_rawData); // Uncomment if using analogWrite for motor driver
  74. }
  75.  
  76. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement