2017-04-15 02:42:23 +02:00
|
|
|
import RPi.GPIO as GPIO
|
2017-04-15 18:43:12 +02:00
|
|
|
from time import sleep
|
2017-04-15 02:42:23 +02:00
|
|
|
class Motor(object):
|
|
|
|
def __init__(self,directionPin,speedPin,directionForward):
|
|
|
|
self.directionPin=directionPin #BCM-Pin
|
|
|
|
self.speedPin=speedPin #BCM-Pin
|
|
|
|
self.directionForward=directionForward; #Enthaelt einen BOOL
|
2017-04-15 18:43:12 +02:00
|
|
|
self.speed=0;
|
2017-04-15 02:42:23 +02:00
|
|
|
GPIO.setup(self.directionPin, GPIO.OUT)
|
|
|
|
GPIO.setup(self.speedPin, GPIO.OUT)
|
2017-04-15 18:43:12 +02:00
|
|
|
GPIO.output(self.speedPin, 0)
|
|
|
|
GPIO.output(self.directionPin, 0)
|
2017-04-15 02:42:23 +02:00
|
|
|
def forward(self):
|
2017-04-15 18:43:12 +02:00
|
|
|
self.stop()
|
2017-04-15 02:42:23 +02:00
|
|
|
GPIO.output(self.directionPin,self.directionForward)
|
2017-04-15 18:43:12 +02:00
|
|
|
GPIO.output(self.speedPin,(not self.directionForward))
|
2017-04-15 02:42:23 +02:00
|
|
|
def backward(self):
|
2017-04-15 18:43:12 +02:00
|
|
|
self.stop()
|
2017-04-15 02:42:23 +02:00
|
|
|
GPIO.output(self.directionPin,(not self.directionForward))
|
2017-04-15 18:43:12 +02:00
|
|
|
GPIO.output(self.speedPin,self.directionForward)
|
2017-04-15 02:42:23 +02:00
|
|
|
def changeSpeed(self,speed):
|
|
|
|
self.speed=speed
|
|
|
|
def stop(self):
|
|
|
|
GPIO.output(self.speedPin, 0)
|
2017-04-15 18:43:12 +02:00
|
|
|
GPIO.output(self.directionPin, 0)
|
|
|
|
sleep(0.02)
|
|
|
|
|
2017-04-15 02:42:23 +02:00
|
|
|
|