Advertisement
pleasedontcode

Dual Motor Control rev_04

May 18th, 2024
930
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: Dual Motor Control
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-05-19 00:29:01
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Ensure the motors are controlled individually: Set */
  21.     /* speed, direction, and movement for each motor */
  22.     /* independently using L298NX2 library functions. */
  23. /****** SYSTEM REQUIREMENT 2 *****/
  24.     /* Ensure precise control of L298N motor drivers: Set */
  25.     /* speed and direction independently for each motor */
  26.     /* using L298NX2 library functions. */
  27. /****** END SYSTEM REQUIREMENTS *****/
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <L298NX2.h> // Include the L298NX2 library
  31. #include <ConfigAssist.h> // Include the ConfigAssist library
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36. void updateOutputs(); // Add function prototype for updateOutputs
  37.  
  38. /***** DEFINITION OF PWM OUTPUT PINS *****/
  39. const uint8_t EN_A = 4; // Define the PWM pin for motor A
  40. const uint8_t EN_B = 16; // Define the PWM pin for motor B
  41.  
  42. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  43. L298NX2 motors(EN_A, 5, 6, EN_B, 7, 8); // Initialize L298NX2 object with pins for motor A and B
  44. ConfigAssist conf; // Initialize ConfigAssist object
  45.  
  46. void setup(void)
  47. {
  48.   // put your setup code here, to run once:
  49.   pinMode(EN_A, OUTPUT); // Set EN_A pin as output
  50.   pinMode(EN_B, OUTPUT); // Set EN_B pin as output
  51.  
  52.   // Initialize ConfigAssist with INI file and configuration dictionary
  53.   conf.init(INI_FILE, appConfigDict_json);
  54.  
  55.   // Ensure the motors are controlled individually
  56.   // Set speed, direction, and movement for each motor independently
  57.   motors.setSpeedA(120);
  58.   motors.setSpeedB(80);
  59. }
  60.  
  61. void loop(void)
  62. {
  63.   // put your main code here, to run repeatedly:
  64.   updateOutputs(); // Refresh output data
  65. }
  66.  
  67. void updateOutputs()
  68. {
  69.   // Ensure precise control of L298N motor drivers
  70.   // Set speed and direction independently for each motor
  71.   motors.runForA(3000, L298N::FORWARD);
  72.   motors.runForB(3000, L298N::BACKWARD);
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement