Advertisement
pleasedontcode

Motor Control rev_07

Jan 29th, 2024
108
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 Uno
  14.     - Source Code created on: 2024-01-29 22:45:59
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Activate the L298N Dual Full-Bridge Motor Driver */
  21.     /* connected to pins D4, D5, and D3. Set IN1 and IN2 */
  22.     /* to HIGH, EN1 to 50% duty cycle, for 3 seconds. */
  23. /****** SYSTEM REQUIREMENT 2 *****/
  24.     /* Refine the user description requirement by */
  25.     /* including the functionality to stop the motor */
  26.     /* connected to the L298N Dual Full-Bridge Motor */
  27.     /* Driver after a duration of 6 seconds. */
  28. /****** END SYSTEM REQUIREMENTS *****/
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include <L298N.h>    // Library for L298N motor driver
  32.  
  33. /****** SYSTEM REQUIREMENTS *****/
  34. /****** SYSTEM REQUIREMENT 1 *****/
  35.   /* Activate the L298N Dual Full-Bridge Motor Driver */
  36.   /* connected to pins D4, D5, and D3. Set IN1 and IN2 */
  37.   /* to HIGH, EN1 to 50% duty cycle, for 3 seconds. */
  38. /****** SYSTEM REQUIREMENT 2 *****/
  39.   /* Refine the user description requirement by */
  40.   /* including the functionality to stop the motor */
  41.   /* connected to the L298N Dual Full-Bridge Motor */
  42.   /* Driver after a duration of 6 seconds. */
  43. /****** END SYSTEM REQUIREMENTS *****/
  44.  
  45. /****** FUNCTION PROTOTYPES *****/
  46. void setup(void);
  47. void loop(void);
  48. void updateOutputs(void);   // Function to update the motor driver outputs
  49.  
  50. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  51. const uint8_t driver_L298NDualFullBridgeMotorDriver_IN1_PIN_D4 = 4;
  52. const uint8_t driver_L298NDualFullBridgeMotorDriver_IN2_PIN_D5 = 5;
  53.  
  54. /***** DEFINITION OF PWM OUTPUT PINS *****/
  55. const uint8_t driver_L298NDualFullBridgeMotorDriver_EN1_PIN_D3 = 3;
  56.  
  57. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  58. L298N motor(driver_L298NDualFullBridgeMotorDriver_EN1_PIN_D3, driver_L298NDualFullBridgeMotorDriver_IN1_PIN_D4, driver_L298NDualFullBridgeMotorDriver_IN2_PIN_D5);
  59.  
  60. void setup(void)
  61. {
  62.   // put your setup code here, to run once:
  63.  
  64.   pinMode(driver_L298NDualFullBridgeMotorDriver_IN1_PIN_D4, OUTPUT);
  65.   pinMode(driver_L298NDualFullBridgeMotorDriver_IN2_PIN_D5, OUTPUT);
  66.   pinMode(driver_L298NDualFullBridgeMotorDriver_EN1_PIN_D3, OUTPUT);
  67.  
  68.   // Activate the L298N Dual Full-Bridge Motor Driver
  69.   digitalWrite(driver_L298NDualFullBridgeMotorDriver_IN1_PIN_D4, HIGH);
  70.   digitalWrite(driver_L298NDualFullBridgeMotorDriver_IN2_PIN_D5, HIGH);
  71.   analogWrite(driver_L298NDualFullBridgeMotorDriver_EN1_PIN_D3, 128);  // 50% duty cycle
  72.  
  73.   delay(3000);  // Wait for 3 seconds
  74.  
  75.   // Stop the motor after a duration of 6 seconds
  76.   delay(3000);  // Wait for 3 seconds
  77.   motor.stop();
  78. }
  79.  
  80. void loop(void)
  81. {
  82.   // put your main code here, to run repeatedly:
  83.  
  84.   updateOutputs(); // Refresh output data
  85. }
  86.  
  87. void updateOutputs()
  88. {
  89.   // Not required for this code example
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement