forked from JamesPoole/WebControlledRobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotors.py
71 lines (64 loc) · 1.36 KB
/
motors.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.OUT)
GPIO.setup(5, GPIO.OUT)
GPIO.setup(7, GPIO.OUT)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
pwm1 = GPIO.PWM(13,100)
pwm2 = GPIO.PWM(15,100)
def forwardGPIO():
pwm1.start(0)
pwm1.ChangeDutyCycle(100)
pwm2.start(0)
pwm2.ChangeDutyCycle(100)
GPIO.output(3,True)
GPIO.output(5,False)
GPIO.output(7,True)
GPIO.output(11,False)
sleep(0.8)
pwm1.stop()
pwm2.stop()
def reverseGPIO():
pwm1.start(0)
pwm1.ChangeDutyCycle(100)
pwm2.start(0)
pwm2.ChangeDutyCycle(100)
GPIO.output(3,False)
GPIO.output(5,True)
GPIO.output(7,False)
GPIO.output(11,True)
sleep(0.8)
pwm1.stop()
pwm2.stop()
def rightGPIO():
pwm1.start(0)
pwm2.start(0)
pwm1.ChangeDutyCycle(80)
pwm2.ChangeDutyCycle(80)
GPIO.output(3,True)
GPIO.output(5,False)
GPIO.output(7,False)
GPIO.output(11,True)
sleep(0.8)
pwm1.stop()
pwm2.stop()
def leftGPIO():
pwm2.start(0)
pwm1.start(0)
pwm2.ChangeDutyCycle(80)
pwm1.ChangeDutyCycle(80)
GPIO.output(7,True)
GPIO.output(11,False)
GPIO.output(3,False)
GPIO.output(5,True)
sleep(0.8)
pwm2.stop()
pwm1.stop()
def stopGPIO():
pwm1.stop()
pwm2.stop()
def clean():
GPIO.cleanup()