-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunboxthemotor.py
54 lines (47 loc) · 1.2 KB
/
unboxthemotor.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
control_pins = [[12, 16, 18, 22], #white
[7,11,13,15], #orange
[29,31,33,35], #green
[19, 21, 23, 24], #red
[36, 38, 40, 37]] #blue
faces = [[1, 1, 4, 1, 0, 0, 3, 5, 5],
[5, 0, 4, 3, 1, 5, 0, 1, 5],
[0, 4, 4, 2, 2, 0, 2, 2, 3],
[3, 3, 1, 4, 3, 1, 2, 3, 1],
[0, 4, 4, 2, 4, 4, 2, 2, 1],
[3, 3, 0, 5, 5, 5, 2, 0, 5]]
for group in control_pins:
for pin in group:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, 0)
seq = [
[1,0,0,1],
[1,0,0,0],
[1,1,0,0],
[0,1,0,0],
[0,1,1,0],
[0,0,1,0],
[0,0,1,1],
[0,0,0,1]
]
steps = len(halfstep_seq)
waitTime = 2 / float(1000)
def rotate(face, times, direction):
degree = int(90 * times * 11.377777777777)
seqPos = 0
for step in range(0, degree):
for pin in range(0, 4):
realPin = control_pins[face][pin]
if seq[seqPos][pin] != 0:
GPIO.output(realPin, True)
else:
GPIO.output(realPin, False)
seqPos += direction
if(seqPos >= steps):
seqPos = 0
if(seqPos < 0):
seqPos = steps + direction
time.sleep(waitTime)
GPIO.cleanup()