Created
March 24, 2022 06:59
-
-
Save jaskiratsingh2000/0eede22f8e2c6e5e87bd8eba0e7e5fb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO as GPIO | |
import time | |
#GPIO Mode (BOARD / BCM) | |
GPIO.setmode(GPIO.BCM) | |
#Setting GPIO Pins for the Motor A | |
DirMotorA = 27 | |
PwmMotorA = 22 | |
#Setting GPIO pins for the Motor B | |
DirMotorB = 23 | |
PwmMotorB = 24 | |
# setting up GPIO Pins direction for the Motor A | |
GPIO.setup(DirMotorA, GPIO.OUT) | |
GPIO.setup(PwmMotorA, GPIO.OUT) | |
# setting up GPIO Pins direction for the Motor B | |
GPIO.setup(DirMotorB, GPIO.OUT) | |
GPIO.setup(PwmMotorB, GPIO.OUT) | |
# Driving the motor Clockwise that is FORWARD | |
#MAX Frequency is 20 Hz | |
leftMotorAPWM = GPIO.PWM(PwmMotorA, 20) | |
leftMotorAPWM.start(0) | |
leftMotorAPWM.ChangeDutyCycle(0) | |
righttMotorAPWM = GPIO.PWM(PwmMotorA, 20) | |
rightMotorAPWM.start(0) | |
rightMotorAPWM.ChangeDutyCycle(0) | |
# Driving the motor Clockwise that is FORWARD | |
GPIO.output(DirMotorA, HIGH) | |
GPIO.output(DirMotorB, LOW) | |
time.sleep(1) | |
# Driving the motor Anti-Clockwise that is BACKWARD | |
GPIO.output(DirMotorA, LOW) | |
GPIO.output(DirMotorB, HIGH) | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment