-
Notifications
You must be signed in to change notification settings - Fork 0
/
motor.py
50 lines (43 loc) · 1 KB
/
motor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# A program to control the movement of a single motor using the RTK MCB!
# Composed by The Raspberry Pi Guy to accompany his tutorial!
# Let's import the modules we will need!
import time
import RPi.GPIO as GPIO
# Next we setup the pins for use!
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
mhz = 100
GPIO.setup(21,GPIO.OUT)
GPIO.setup(20,GPIO.OUT)
GPIO.setup(16,GPIO.OUT)
GPIO.setup(12,GPIO.OUT)
m1 = GPIO.PWM(21, mhz)
m2 = GPIO.PWM(20, mhz)
m3 = GPIO.PWM(16, mhz)
m4 = GPIO.PWM(12, mhz)
def backward(speed):
if(speed > 100):
speed = 100
m1.start(speed)
GPIO.output(20, False)
m3.start(speed)
GPIO.output(12, False)
def forward(speed):
if(speed > 100):
speed = 100
m2.start(speed)
GPIO.output(21, False)
m4.start(speed)
GPIO.output(16, False)
def stop():
m1.stop()
m2.stop()
m3.stop()
m4.stop()
def finish():
print('Finishing up!')
GPIO.output(21, False)
GPIO.output(20, False)
GPIO.output(16, False)
GPIO.output(12, False)
quit()