-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0-Configuracao_GPIO.py
38 lines (31 loc) · 1.1 KB
/
0-Configuracao_GPIO.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
import RPi.GPIO as GPIO # sudo apt-get install python-rpi.gpio
class Driver:
def __init__(self):
GPIO.setmode(GPIO.BOARD)
self.R_EN = 21
self.L_EN = 22
self.RPWM = 23
self.LPWM = 24
GPIO.setup(self.R_EN, GPIO.OUT)
GPIO.setup(self.RPWM, GPIO.OUT)
GPIO.setup(self.L_EN, GPIO.OUT)
GPIO.setup(self.LPWM, GPIO.OUT)
GPIO.output(self.R_EN, True)
GPIO.output(self.L_EN, True)
def neutral(self):
GPIO.output(self.RPWM, False) # Stop turning right
GPIO.output(self.LPWM, False) # stop turning left
def right(self):
GPIO.output(self.LPWM, False) # stop turning left
GPIO.output(self.RPWM, True) # start turning right
def left(self):
GPIO.output(self.RPWM, False) # Stop turning right
GPIO.output(self.LPWM, True) # start turning left
def cleanup(self):
GPIO.cleanup()
from motorlib import Driver
driver = Driver()
driver.right() # turns right
driver.left() # turns left
driver.neutral() # stops turning
driver.cleanup()