-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGRBL_Control.pde
146 lines (122 loc) · 2.36 KB
/
GRBL_Control.pde
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// -------------------------------------------------------------------------------------------------
// GRBL Sheild Control Library
// This library allows control of the GRBL shield without using the GRBL firmware
//
// A project of HackPittsburgh (http://www.hackpittsburgh.org)
//
// Copyright (c) 2011 Matt Stultz ([email protected])
// Licensed under the MIT license: http://creativecommons.org/licenses/MIT
// -------------------------------------------------------------------------------------------------
// Define Step Pins
#define STEP_X_PIN 2
#define STEP_Y_PIN 3
#define STEP_Z_PIN 4
// Define Direction Pins
#define DIR_X_PIN 5
#define DIR_Y_PIN 6
#define DIR_Z_PIN 7
// Variable for setting the period between steps in miliseconds.
int SPEED;
// Initialize the GRBL shield
void InitGRBL ()
{
pinMode(STEP_X_PIN, OUTPUT);
pinMode(STEP_Y_PIN, OUTPUT);
pinMode(STEP_Z_PIN, OUTPUT);
pinMode(DIR_X_PIN, OUTPUT);
pinMode(DIR_Y_PIN, OUTPUT);
pinMode(DIR_Z_PIN, OUTPUT);
}
// Set Speed in steps/second
void SetSpeed (int StepsPerSecond)
{
SPEED = 1000 / StepsPerSecond;
}
// Step the X axis
void Move_X (int steps)
{
if (steps < 0)
{
digitalWrite(DIR_X_PIN, LOW);
steps = steps * -1;
}
else
{
digitalWrite(DIR_X_PIN, HIGH);
}
for (x=0; x < steps; x++)
{
digitalWrite(STEP_X_PIN,HIGH);
delay(20);
digitalWrite(STEP_X_PIN,LOW);
delay(SPEED - 20);
}
}
// Step the Y axis
void Move_Y (int steps)
{
if (steps < 0)
{
digitalWrite(DIR_Y_PIN, LOW);
steps = steps * -1;
}
else
{
digitalWrite(DIR_Y_PIN, HIGH);
}
for (x=0; x < steps; x++)
{
digitalWrite(STEP_Y_PIN,HIGH);
delay(20);
digitalWrite(STEP_Y_PIN,LOW);
delay(SPEED - 20);
}
}
// Step the Z axis
void Move_Z (int steps)
{
if (steps < 0)
{
digitalWrite(DIR_Z_PIN, LOW);
steps = steps * -1;
}
else
{
digitalWrite(DIR_Z_PIN, HIGH);
}
for (x=0; x < steps; x++)
{
digitalWrite(STEP_Z_PIN,HIGH);
delay(20);
digitalWrite(STEP_Z_PIN,LOW);
delay(SPEED - 20);
}
}
// Move all Axes
// Find largest change
int MaxMoves(int X, int Y, int Z)
{
return max(x,max(Y,Z));
// if (X>Y)
// {
// if (X>Z)
// {
// return X;
// }
// else
// {
// return Z;
// }
// }
// Else
// {
// if (Y>Z)
// {
// return Y;
// }
// else
// {
// return Z;
// }
// }
}