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: ESP32 DevKit V1
- - Source Code created on: 2024-12-27 03:51:08
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* this code is stopping the motors on forward api */
- /* call can you make the motors move backward on */
- /* backward api call and stop it on pressing stop and */
- /* foward on forward api call */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <Adafruit_MotorShield.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void moveForward();
- void moveBackward();
- void stopMotors();
- /****** GLOBAL VARIABLES *****/
- Adafruit_MotorShield motorShield = Adafruit_MotorShield(); // Create motor shield object
- Adafruit_DCMotor *motor1 = motorShield.getMotor(1); // Get motor 1
- Adafruit_DCMotor *motor2 = motorShield.getMotor(2); // Get motor 2
- void setup(void)
- {
- // Initialize the motor shield
- motorShield.begin();
- }
- void loop(void)
- {
- // Example API calls
- moveForward(); // Call to move forward
- delay(2000); // Move forward for 2 seconds
- stopMotors(); // Stop the motors
- delay(1000); // Wait for 1 second
- moveBackward(); // Call to move backward
- delay(2000); // Move backward for 2 seconds
- stopMotors(); // Stop the motors
- }
- /****** FUNCTION IMPLEMENTATIONS *****/
- void moveForward() {
- motor1->setSpeed(255); // Set speed to maximum
- motor1->run(FORWARD); // Move motor 1 forward
- motor2->setSpeed(255); // Set speed to maximum
- motor2->run(FORWARD); // Move motor 2 forward
- }
- void moveBackward() {
- motor1->setSpeed(255); // Set speed to maximum
- motor1->run(BACKWARD); // Move motor 1 backward
- motor2->setSpeed(255); // Set speed to maximum
- motor2->run(BACKWARD); // Move motor 2 backward
- }
- void stopMotors() {
- motor1->run(RELEASE); // Stop motor 1
- motor2->run(RELEASE); // Stop motor 2
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement