-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmotor.py
29 lines (23 loc) · 853 Bytes
/
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
import RPi.GPIO as GPIO
class Motor:
"""
Add speed, acceleration rate.
"""
def __init__(self, enable_pin, forward_pin, reverse_pin):
self.forward_pin = forward_pin
self.reverse_pin = reverse_pin
self.enable_pin = enable_pin
GPIO.setup(self.enable_pin, GPIO.OUT)
GPIO.setup(self.forward_pin, GPIO.OUT)
GPIO.setup(self.reverse_pin, GPIO.OUT)
GPIO.output(self.enable_pin, True)
self.PWM = GPIO.PWM(enable_pin, 1000)
def forward(self):
GPIO.output(self.forward_pin, True)
GPIO.output(self.reverse_pin, False)
def reverse(self):
GPIO.output(self.forward_pin, False)
GPIO.output(self.reverse_pin, True)
def stop(self):
GPIO.output(self.forward_pin, False)
GPIO.output(self.reverse_pin, False)