- Sun May 04, 2014 9:13 am
#170766
Hello all, new here. I've been messing around with arduino for about a year now and have a lot to learn. I have a 12v NEMA17 4 wire stepper that I'm driving with the BED. It works great. For my project I need to 'release' the stepper so I can turn the motor by hand from time to time. I found the following code on youtube from NYC CNC which was a big help. I was looking for some help on how the code should look. Thank you in advance.
Code: Select all
int Fire; //fire button
int Ttable; //turn table button
int feedspeed = 400; //feed stpper speed less is faster
int totalsteps = 2000; //total number of steps set for distance
int stepcount = 0; //
int Firestate = 0; //
int Ttablestate = 0; //
void setup()
{
pinMode(4,INPUT); // fire button pin
pinMode(5,INPUT); // turn table button pin
pinMode(10,OUTPUT); // stepper direction pin
pinMode(11,OUTPUT); //stepper step pin
digitalWrite(10,LOW); //
digitalWrite(11,LOW); //
}
void loop() {
Fire = digitalRead(4); //reads pin 4
Ttable = digitalRead(5); //reads pin 5
if (Ttable == LOW && Ttablestate == 0)
{
while(stepcount < totalsteps)
{
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
delayMicroseconds(feedspeed);
digitalWrite(11,LOW);
delayMicroseconds(feedspeed);
stepcount++;
}
stepcount = 0;
Ttablestate = 1;
}
if (Fire == LOW && Firestate == 0)
{
while(stepcount < totalsteps)
{
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
delayMicroseconds(feedspeed);
digitalWrite(11,LOW);
delayMicroseconds(feedspeed);
stepcount++;
}
stepcount = 0;
Firestate = 1;
}
if(Fire == HIGH && Firestate == 1)
{
Firestate = 0;
}
if(Ttable == HIGH && Ttablestate == 1)
{
Ttablestate = 0;
}
}