engine class and test

This commit is contained in:
Thomas Klaehn 2016-03-20 17:16:20 +00:00 committed by Thomas Klaehn
parent 45ff4cbc22
commit 9eea802e39
2 changed files with 35 additions and 20 deletions

View File

@ -1,27 +1,26 @@
from gpio import gpio
class engine:
def __init__(self, gpio_1 = 13, gpio_2 = 19):
self.gpio_1 = gpio_1
self.gpio_2 = gpio_2
self.gpio_1 = gpio(gpio_1)
self.gpio_2 = gpio(gpio_2)
# export gpio's
n = "/sys/class/gpio/gpio" + str(self.gpio_1)
if not islink(n):
f = open("sys/class/gpio/export", "w")
f.write(str(self.gpio_1)
f = open("sys/class/gpio/gpio" + str(self.gpio_1) +\
"/value", "w")
f.write("out")
n = "/sys/class/gpio/gpio" + str(self.gpio_2)
if not islink(n):
f = open("sys/class/gpio/export", "w")
f.write(str(self.gpio_2)
f = open("sys/class/gpio/gpio" + str(self.gpio_2) +\
"/value", "w")
f.write("out")
self.gpio_1.export()
self.gpio_1.direction("out")
self.gpio_2.export()
self.gpio_2.direction("out")
self.stop()
def stop(self):
self.gpio_1.set(0)
self.gpio_2.set(0)
def run_up(self):
self.gpio_1.set(1)
self.gpio_2.set(0)
def run_down(self):
self.gpio_1.set(0)
self.gpio_2.set(1)

16
engine_test.py Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/python2
from engine import engine
from time import sleep
eng = engine(13, 19)
while True:
eng.stop()
print "engine stop"
sleep(3)
eng.run_up()
print "engine up"
sleep(3)
eng.run_down()
print "engine down"
sleep(3)