-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstepmotor.py
More file actions
74 lines (62 loc) · 1.91 KB
/
Copy pathstepmotor.py
File metadata and controls
74 lines (62 loc) · 1.91 KB
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
from machine import Pin
import time
phasecw = [0x08,0x04,0x02,0x01]
phaseccw = [0x01,0x02,0x04,0x08]
out=0x01
class mystepmotor(object):
def __init__(self, A: int=14, B: int=13, C: int=12, D: int=11):
self._A = Pin(A,Pin.OUT,0)
self._B = Pin(B,Pin.OUT,0)
self._C = Pin(C,Pin.OUT,0)
self._D = Pin(D,Pin.OUT,0)
def _motorcontrol(self,data):
if data == 0x08:
self._A.on()
self._B.off()
self._C.off()
self._D.off()
if data == 0x04:
self._A.off()
self._B.on()
self._C.off()
self._D.off()
if data == 0x02:
self._A.off()
self._B.off()
self._C.on()
self._D.off()
if data == 0x01:
self._A.off()
self._B.off()
self._C.off()
self._D.on()
if data == 0x00:
self._A.off()
self._B.off()
self._C.off()
self._D.off()
def moveOneStep(self,direction):
global out
if direction == 1:
if out!=0x08:
out=out<<1
else:
out=0x01
else:
if direction == 0:
if out!=0x01:
out=out>>1
else:
out=0x08
self._motorcontrol(out)
def moveSteps(self,direction,steps,us):
for i in range(steps):
self.moveOneStep(direction)
time.sleep_us(us)
def moveAround(self,direction,turns,us):
for i in range(turns):
self.moveSteps(direction,32*64,us)
def moveAngle(self,angles,us):
self.moveSteps(direction,32*64//angles,us)
def stop(self):
self._motorcontrol(0x00)