int dirpin = 2; //stepper direction: HIGH=DOWN, LOW=UP
int steppin = 3;
int z_low_ls = 12; //Lower Z-axis limit switch
int z_high_ls = 13; //Upper Z-axis limit switch
int zero_torch = 6; //Zero torch on workpiece. HIGH: no contact with workpiece. LOW: Zero'd torch on workpiece
int ready_thc = 8; //LOW: no signal to start cutting. HIGH: begin cut process
int s_ready_thc = 0; //Condition
int s_zero_torch = 0; //Condition
int s_z_high_ls = 0; //Condition
int s_z_low_ls = 0; //Condition
//Setup the I/O
void setup()
{
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
pinMode(z_low_ls, INPUT);
pinMode(z_high_ls, INPUT);
pinMode(zero_torch, INPUT);
pinMode(ready_thc, INPUT);
}
//Move the Z-axis down
void move_down()
{
{
digitalWrite(dirpin, HIGH);
digitalWrite(steppin, LOW);
digitalWrite(steppin, HIGH);
delayMicroseconds(200);
}
}
//Move the Z-axis up
void move_up()
{
{
digitalWrite(dirpin, LOW);
digitalWrite(steppin, LOW);
digitalWrite(steppin, HIGH);
delayMicroseconds(200);
}
}
//If Mach3 hasn't sent a "start cut" signal, return the torch to the top "home position"
void home_pos()
{
s_z_high_ls=digitalRead(z_high_ls);
if (s_z_high_ls == HIGH)
{
move_up();
}
}
//Once Mach3 gets "start cut" signal, zero the torch to the workpiece
void zero_workpiece()
{
s_zero_torch=digitalRead(zero_torch);
if (s_zero_torch == HIGH)
{
move_down();
}
}
/*
void pierce_height()
{
for (int i=0; i<4000; i++)
{
digitalWrite(dirpin, LOW);
digitalWrite(steppin, LOW);
digitalWrite(steppin, HIGH);
delayMicroseconds(500);
}
}
*/
//Program loop
void loop()
{
s_ready_thc=digitalRead(ready_thc);
s_z_high_ls=digitalRead(z_high_ls);
s_zero_torch=digitalRead(zero_torch);
if (s_ready_thc == LOW) //If the THC hasn't received a signal from Mach3, go ahead and home by traversing the Z axis to the top until the Z upper limit switch is HIGH
{
home_pos();
}
while (s_ready_thc != LOW); //If the THC has received a signal from Mach3, start the cut process
{
zero_workpiece();
}
}