Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **Motor Control**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-11-28 19:01:50
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* I have stacked hw 130 l293d on the arduino and */
- /* connected one dc motor to m1 and n20 gear box to */
- /* m3 .we have also attached 1 servo motor to */
- /* servo_1 on the driver. Write the code for it */
- /* such that M1 and m3 connected motors run forward */
- /* and reverse */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <AFMotor.h> // Library for controlling DC motors
- #include <Servo.h> // Library for controlling servo motors
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Motor and Servo declarations
- AF_DCMotor motor1(1); // Motor connected to M1
- AF_DCMotor motor3(3); // Motor connected to M3
- Servo myServo; // Servo object
- void setup(void)
- {
- // Initialize motors
- motor1.setSpeed(255); // Set speed for motor1 (0-255)
- motor3.setSpeed(255); // Set speed for motor3 (0-255)
- // Attach the servo to pin 9
- myServo.attach(9); // Assuming the servo is connected to pin 9
- }
- void loop(void)
- {
- // Run motors forward
- motor1.run(FORWARD);
- motor3.run(FORWARD);
- delay(2000); // Run forward for 2 seconds
- // Run motors backward
- motor1.run(BACKWARD);
- motor3.run(BACKWARD);
- delay(2000); // Run backward for 2 seconds
- // Stop motors
- motor1.run(RELEASE);
- motor3.run(RELEASE);
- delay(1000); // Stop for 1 second
- // Move servo to 0 degrees
- myServo.write(0);
- delay(1000); // Wait for 1 second
- // Move servo to 90 degrees
- myServo.write(90);
- delay(1000); // Wait for 1 second
- // Move servo to 180 degrees
- myServo.write(180);
- delay(1000); // Wait for 1 second
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement