diff --git a/engine.py b/engine.py index f9aa2a7..b7be713 100644 --- a/engine.py +++ b/engine.py @@ -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) + diff --git a/engine_test.py b/engine_test.py new file mode 100755 index 0000000..5c64488 --- /dev/null +++ b/engine_test.py @@ -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) +