-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep_motor_30_08.c
98 lines (81 loc) · 2.12 KB
/
step_motor_30_08.c
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
97
98
#include <AccelStepper.h>
// The X Stepper pins
#define STEPPER1_DIR_PIN 4
#define STEPPER1_STEP_PIN 3
// The Y stepper pins
#define STEPPER2_DIR_PIN 6
#define STEPPER2_STEP_PIN 5
#define STEPPER3_DIR_PIN 8
#define STEPPER3_STEP_PIN 7
#define STEPPER4_DIR_PIN 12
#define STEPPER4_STEP_PIN 11
#define UP -550
#define DOWN -410
// Define some steppers and the pins the will use
AccelStepper stepper1(AccelStepper::DRIVER, STEPPER1_STEP_PIN, STEPPER1_DIR_PIN);
AccelStepper stepper2(AccelStepper::DRIVER, STEPPER2_STEP_PIN, STEPPER2_DIR_PIN);
AccelStepper stepper3(AccelStepper::DRIVER, STEPPER3_STEP_PIN, STEPPER3_DIR_PIN);
AccelStepper stepper4(AccelStepper::DRIVER, STEPPER4_STEP_PIN, STEPPER4_DIR_PIN);
int i = 0;
void setup()
{
pinMode(8,OUTPUT);
digitalWrite(8,LOW);
stepper1.setMaxSpeed(150.0);
stepper1.setAcceleration(500.0);
stepper1.moveTo(UP);
stepper2.setMaxSpeed(150.0);
stepper2.setAcceleration(500.0);
stepper2.moveTo(UP);
stepper3.setMaxSpeed(150.0);
stepper3.setAcceleration(500.0);
stepper3.moveTo(UP);
stepper4.setMaxSpeed(150.0);
stepper4.setAcceleration(500.0);
stepper4.moveTo(UP);
while (stepper1.distanceToGo() != 0 && stepper2.distanceToGo() != 0 && stepper3.distanceToGo() != 0 && stepper4.distanceToGo() != 0)
{
stepper1.run();
stepper2.run();
stepper3.run();
stepper4.run();
}
stepper1.setAcceleration(500.0);
stepper2.setAcceleration(500.0);
stepper3.setAcceleration(500.0);
stepper4.setAcceleration(500.0);
delay(150);
}
void loop()
{
// Change direction at the limits
if (stepper1.distanceToGo() == 0) {
if (i % 2 == 0)
stepper1.moveTo(DOWN);
else
stepper1.moveTo(UP);
}
if (stepper2.distanceToGo() == 0) {
if (i % 2 == 0)
stepper2.moveTo(DOWN);
else
stepper2.moveTo(UP);
}
if (stepper3.distanceToGo() == 0) {
if (i % 2 == 0)
stepper3.moveTo(DOWN);
else
stepper3.moveTo(UP);
}
if (stepper4.distanceToGo() == 0) {
if (i % 2 == 0)
stepper4.moveTo(DOWN);
else
stepper4.moveTo(UP);
}
++i;
stepper1.run();
stepper2.run();
stepper3.run();
stepper4.run();
}