Advertisement
pleasedontcode

Motor Control rev_01

Mar 14th, 2024
58
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: Motor Control
  13.     - Source Code compiled for: Arduino Mega
  14.     - Source Code created on: 2024-03-14 07:10:25
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* make an Arduino troubleshooting program for motor */
  21.     /* pins 8 and 9  by using encoder pins 17 and 367 */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <CarPWMMotorControl.hpp>   //https://github.com/ArminJo/PWMMotorControl
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t encoder_PIN_D2 = 2;
  33.  
  34. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  35. CarPWMMotorControl motorControl; // Instantiate the CarPWMMotorControl object
  36.  
  37. // Define motor control pin numbers
  38. const uint8_t RIGHT_MOTOR_FORWARD_PIN = 3;
  39. const uint8_t RIGHT_MOTOR_BACKWARD_PIN = 4;
  40. const uint8_t RIGHT_MOTOR_PWM_PIN = 5;
  41. const uint8_t RIGHT_MOTOR_INTERRUPT = 0;
  42.  
  43. void setup(void) {
  44.   // put your setup code here, to run once:
  45.   pinMode(encoder_PIN_D2, INPUT);
  46.  
  47.   // Initialize the motor control object
  48.   motorControl.init(RIGHT_MOTOR_FORWARD_PIN, RIGHT_MOTOR_BACKWARD_PIN, RIGHT_MOTOR_PWM_PIN, RIGHT_MOTOR_INTERRUPT, STOP_MODE_BRAKE, STOP_MODE_RELEASE);
  49. }
  50.  
  51. void loop(void) {
  52.   // put your main code here, to run repeatedly:
  53.  
  54.   // Example usage of the motor control object
  55.  
  56.   // Set the drive speed to maximum forward
  57.   motorControl.setDriveSpeedPWM(255);
  58.  
  59.   // Delay for 2 seconds
  60.   delay(2000);
  61.  
  62.   // Set the drive speed to maximum backward
  63.   motorControl.setDriveSpeedPWM(-255);
  64.  
  65.   // Delay for 2 seconds
  66.   delay(2000);
  67.  
  68.   // Stop the motor
  69.   motorControl.stop();
  70.  
  71.   // Delay for 2 seconds
  72.   delay(2000);
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement