-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot.py
96 lines (79 loc) · 1.99 KB
/
boot.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from machine import Pin, Timer
import time, uos
#Define Pins------------------------
dirPin = Pin(15, Pin.OUT, value = 0)
stpPin = Pin(2, Pin.OUT, value = 0)
slpPin = Pin(4, Pin.OUT, value = 1)
rstPin = Pin(16, Pin.OUT, value = 1)
m2Pin = Pin(17, Pin.OUT, value = 0)
m1Pin = Pin(5, Pin.OUT, value = 1)
m0Pin = Pin(18, Pin.OUT, value = 0)
enaPin = Pin(19, Pin.OUT, value = 0)
print("Starting: quarter-step-mode, driver enabled")
def setMicroSteps(uSteps):
if uSteps == 32:
m0Pin.value(1)
m1Pin.value(0)
m2Pin.value(1)
elif uSteps == 16:
m0Pin.value(0)
m1Pin.value(0)
m2Pin.value(1)
elif uSteps == 8:
m0Pin.value(1)
m1Pin.value(1)
m2Pin.value(0)
elif uSteps == 4:
m0Pin.value(0)
m1Pin.value(1)
m2Pin.value(0)
elif uSteps == 2:
m0Pin.value(1)
m1Pin.value(0)
m2Pin.value(0)
elif uSteps == 1:
m0Pin.value(0)
m1Pin.value(0)
m2Pin.value(0)
else:
print("Error: # of µ-steps not supported: using halfstep-mode")
m0Pin.value(1)
m1Pin.value(0)
m2Pin.value(0)
def moveStep(dir):
if dir == 0 or dir == 1:
dirPin.value(dir)
time.sleep_us(100)
stpPin.value(1)
time.sleep_us(200)
stpPin.value(0)
#print("Moved")
else:
print("Error: incorrect direction value, use 0 or 1")
def driverSlp():
slpPin.value(0)
def driverWake():
slpPin.value(1)
time.sleep_ms(3)
def flipMirror(self):
if "direction" not in globals():
global direction
direction = 0
for i in range(200):
moveStep(direction)
time.sleep_ms(10)
direction ^= 1
def getFreq():
try:
f = open("freq.txt", "r")
return int(f.read())
except:
print("Error: could not get frequency. freq.txt file missing or corrupted?")
return 30
tim0 = Timer(0)
tim0.init(period = getFreq() * 1000, mode = Timer.PERIODIC, callback = flipMirror)
#try:
# while True:
# pass
#except KeyboardInterrupt:
# tim0.deinit()