-
Notifications
You must be signed in to change notification settings - Fork 0
/
StepperFourPhaseFiveWire.cpp
80 lines (69 loc) · 1.13 KB
/
StepperFourPhaseFiveWire.cpp
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
/*
* StepperFourPhaseFiveWire.cpp
*
* Created on: 23 Apr 2017
* Author: williambagshaw
*/
#include "StepperFourPhaseFiveWire.h"
StepperFourPhaseFiveWire::StepperFourPhaseFiveWire
(
Pin p1,
Pin p2,
Pin p3,
Pin p4,
StepperFourPhaseFiveWire::Mode mode
):m_target{0},m_position{0},m_mode{mode},m_pins{p1,p2,p3,p4},m_step{0}
{
}
void StepperFourPhaseFiveWire::SetPosition(Coordinate p)
{
m_position = p;
m_target = p;
//m_step is unchanged.
}
void StepperFourPhaseFiveWire::Update(void)
{
int i;
for(i = 0; i < 4; i++)
{
Write(m_pins[i],m_modes[m_mode][m_step][i]);
}
}
void StepperFourPhaseFiveWire::BreakOff(void)
{
int i;
for(i = 0; i < 4; i++)
{
Write(m_pins[i],false);
}
}
void StepperFourPhaseFiveWire::BreakOn(void)
{
Update();
}
bool StepperFourPhaseFiveWire::Step(void)
{
if(m_target > m_position)
{
// Forward step.
m_step++;
if(m_step >= NUM_STEPS)
{
m_step = 0;
}
m_position++;
Update();
}
else if(m_target < m_position)
{
// Backward step.
m_step--;
if(m_step < 0)
{
m_step = NUM_STEPS - 1;
}
m_position--;
Update();
}
return (m_target != m_position);
}