mirror of https://github.com/Trivernis/spydian.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
140 lines
2.9 KiB
Python
140 lines
2.9 KiB
Python
6 years ago
|
import time
|
||
|
|
||
7 years ago
|
import RPi.GPIO as GPIO
|
||
6 years ago
|
|
||
7 years ago
|
GPIO.setmode(GPIO.BCM)
|
||
|
GPIO.setwarnings(False)
|
||
|
|
||
6 years ago
|
|
||
|
def full_step(phase, pins):
|
||
7 years ago
|
pin1, pin2, pin3, pin4 = pins
|
||
|
|
||
6 years ago
|
if phase == 0:
|
||
7 years ago
|
GPIO.output(pin1, 0)
|
||
|
GPIO.output(pin2, 0)
|
||
|
GPIO.output(pin3, 0)
|
||
|
GPIO.output(pin4, 0)
|
||
|
|
||
6 years ago
|
if phase == 1:
|
||
7 years ago
|
GPIO.output(pin1, 1)
|
||
|
GPIO.output(pin2, 1)
|
||
|
GPIO.output(pin3, 0)
|
||
|
GPIO.output(pin4, 0)
|
||
|
|
||
6 years ago
|
if phase == 2:
|
||
7 years ago
|
GPIO.output(pin1, 0)
|
||
|
GPIO.output(pin2, 1)
|
||
|
GPIO.output(pin3, 1)
|
||
|
GPIO.output(pin4, 0)
|
||
|
|
||
6 years ago
|
if phase == 3:
|
||
7 years ago
|
GPIO.output(pin1, 0)
|
||
|
GPIO.output(pin2, 0)
|
||
|
GPIO.output(pin3, 1)
|
||
|
GPIO.output(pin4, 1)
|
||
|
|
||
6 years ago
|
if phase == 4:
|
||
7 years ago
|
GPIO.output(pin1, 1)
|
||
|
GPIO.output(pin2, 0)
|
||
|
GPIO.output(pin3, 0)
|
||
|
GPIO.output(pin4, 1)
|
||
|
|
||
6 years ago
|
|
||
|
def half_step(phase, pins):
|
||
7 years ago
|
pin1, pin2, pin3, pin4 = pins
|
||
|
|
||
6 years ago
|
if phase == 0:
|
||
7 years ago
|
GPIO.output(pin1, 0)
|
||
|
GPIO.output(pin2, 0)
|
||
|
GPIO.output(pin3, 0)
|
||
|
GPIO.output(pin4, 0)
|
||
|
|
||
6 years ago
|
if phase == 1:
|
||
7 years ago
|
GPIO.output(pin1, 1)
|
||
|
GPIO.output(pin2, 0)
|
||
|
GPIO.output(pin3, 0)
|
||
|
GPIO.output(pin4, 0)
|
||
|
|
||
6 years ago
|
if phase == 2:
|
||
7 years ago
|
GPIO.output(pin1, 1)
|
||
|
GPIO.output(pin2, 1)
|
||
|
GPIO.output(pin3, 0)
|
||
|
GPIO.output(pin4, 0)
|
||
|
|
||
6 years ago
|
if phase == 3:
|
||
7 years ago
|
GPIO.output(pin1, 0)
|
||
|
GPIO.output(pin2, 1)
|
||
|
GPIO.output(pin3, 0)
|
||
|
GPIO.output(pin4, 0)
|
||
|
|
||
6 years ago
|
if phase == 4:
|
||
7 years ago
|
GPIO.output(pin1, 0)
|
||
|
GPIO.output(pin2, 1)
|
||
|
GPIO.output(pin3, 1)
|
||
|
GPIO.output(pin4, 0)
|
||
|
|
||
6 years ago
|
if phase == 5:
|
||
7 years ago
|
GPIO.output(pin1, 0)
|
||
|
GPIO.output(pin2, 0)
|
||
|
GPIO.output(pin3, 1)
|
||
|
GPIO.output(pin4, 0)
|
||
|
|
||
6 years ago
|
if phase == 6:
|
||
7 years ago
|
GPIO.output(pin1, 0)
|
||
|
GPIO.output(pin2, 0)
|
||
|
GPIO.output(pin3, 1)
|
||
|
GPIO.output(pin4, 1)
|
||
|
|
||
6 years ago
|
if phase == 7:
|
||
7 years ago
|
GPIO.output(pin1, 0)
|
||
|
GPIO.output(pin2, 0)
|
||
|
GPIO.output(pin3, 0)
|
||
|
GPIO.output(pin4, 1)
|
||
|
|
||
6 years ago
|
if phase == 8:
|
||
7 years ago
|
GPIO.output(pin1, 1)
|
||
|
GPIO.output(pin2, 0)
|
||
|
GPIO.output(pin3, 0)
|
||
|
GPIO.output(pin4, 1)
|
||
|
|
||
6 years ago
|
|
||
7 years ago
|
def full_phase(pins):
|
||
6 years ago
|
# order=[1,2,3,4]
|
||
|
order = [4, 3, 2, 1]
|
||
7 years ago
|
print("Moving in {}-order".format(order))
|
||
|
for i in order:
|
||
|
full_step(i, pins)
|
||
|
time.sleep(0.005)
|
||
|
|
||
6 years ago
|
|
||
7 years ago
|
def half_phase(pins):
|
||
6 years ago
|
for i in range(0, 8):
|
||
|
half_step(i, pins)
|
||
7 years ago
|
time.sleep(0.0025)
|
||
|
|
||
6 years ago
|
|
||
7 years ago
|
def forward(pins):
|
||
|
half_phase(pins)
|
||
|
|
||
6 years ago
|
|
||
7 years ago
|
def backward(pins):
|
||
|
(pins[0], pins[1], pins[2], pins[3]) = (pins[1], pins[0], pins[2], pins[3])
|
||
|
half_phase(pins)
|
||
|
|
||
6 years ago
|
|
||
|
if __name__ == '__main__':
|
||
|
pins = [6, 13, 19, 26]
|
||
7 years ago
|
for pin in pins:
|
||
|
GPIO.setup(pin, GPIO.OUT)
|
||
|
while True:
|
||
|
try:
|
||
6 years ago
|
start = time.time()
|
||
|
while (time.time() < start + 10):
|
||
7 years ago
|
forward(pins)
|
||
6 years ago
|
start = time.time()
|
||
|
while (time.time() < start + 10):
|
||
7 years ago
|
backward(pins)
|
||
|
except KeyboardInterrupt:
|
||
|
break
|
||
|
GPIO.cleanup()
|