-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stepper.h
83 lines (74 loc) · 1.7 KB
/
Stepper.h
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
// pins 2, 3, 4, 5, 6, 7
class StepperOne
{
private:
const byte pins = ~B11111100;
const byte outputs[8] = {B11000000, // full a
B11001100,
B00001100, // full b
B10101100,
B10100000, // rev a
B10110100,
B00010100, // rev b
B11010100};
byte output = 0;
const byte stepSize;
int steps = 0;
public:
void spin() { PORTD = pins & PORTD; }
StepperOne( const bool h=false ) : stepSize(h ? 1 : 2)
{
DDRD |= ~pins;
}
void step( byte dir=0 )
{
if( dir )
{
output += stepSize;
steps += stepSize;
}
else
{
output -= stepSize;
steps -= stepSize;
}
PORTD = ( pins & PORTD ) | outputs[ output%8 ];
}
};
// pins 8, 9, 10, 11, 12, 13
class StepperTwo
{
private:
const byte pins = ~B00111111;
const byte outputs[8] = {B00110000, // full a
B00110011,
B00000011, // full b
B00101011,
B00101000, // rev a
B00101101,
B00000101, // rev b
B00110101};
byte output = 0;
const byte stepSize;
int steps = 0;
public:
void spin() { PORTB = pins & PORTB; }
StepperTwo( const bool h=false ) : stepSize(h ? 1 : 2)
{
DDRB |= ~pins;
}
void step( byte dir=0 )
{
if( dir )
{
output += stepSize;
steps += stepSize;
}
else
{
output -= stepSize;
steps -= stepSize;
}
PORTB = ( pins & PORTB ) | outputs[ output%8 ];
}
};