Advertisement
pleasedontcode

**Servo Control** rev_01

Dec 16th, 2024
41
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: **Servo Control**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-12-16 11:54:06
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The system shall control a motor car's movement */
  21.     /* using specific connected components, enabling */
  22.     /* precise navigation and speed adjustments based on */
  23.     /* user inputs. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <Servo.h> // Include the Servo library for motor control
  30. #include <AFMotor.h> // Include the AFMotor library for motor control
  31. #include <Wire.h> // Include the Wire library for I2C communication
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36.  
  37. // Create Servo objects for controlling the motors
  38. Servo leftMotor; // Left motor
  39. Servo rightMotor; // Right motor
  40.  
  41. // Motor speed variables
  42. int leftMotorSpeed = 0;
  43. int rightMotorSpeed = 0;
  44.  
  45. void setup(void)
  46. {
  47.     // Attach the motors to the appropriate pins
  48.     leftMotor.attach(9); // Attach left motor to pin 9
  49.     rightMotor.attach(10); // Attach right motor to pin 10
  50.  
  51.     // Initialize motor speeds
  52.     leftMotorSpeed = 0;
  53.     rightMotorSpeed = 0;
  54. }
  55.  
  56. void loop(void)
  57. {
  58.     // Example of controlling the motor speeds
  59.     // Here you can add your logic to change speeds based on user input
  60.     leftMotorSpeed = 1500; // Set left motor speed
  61.     rightMotorSpeed = 1500; // Set right motor speed
  62.  
  63.     // Write the speeds to the motors
  64.     leftMotor.write(leftMotorSpeed);
  65.     rightMotor.write(rightMotorSpeed);
  66.  
  67.     // Add a delay to allow the motors to run for a while
  68.     delay(1000);
  69.  
  70.     // Stop the motors
  71.     leftMotorSpeed = 0;
  72.     rightMotorSpeed = 0;
  73.  
  74.     // Write the stop command to the motors
  75.     leftMotor.write(leftMotorSpeed);
  76.     rightMotor.write(rightMotorSpeed);
  77.  
  78.     // Add a delay before the next loop iteration
  79.     delay(1000);
  80. }
  81.  
  82. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement