#include
//define motor control with a constant
Const int enablePin=8;
Const int x_Step_Pin=2;
Const int x_Dir_Pin=5;
Const int y_Step_Pin=3;
Const int y_Dir_Pin=6;
Const int z_Step_Pin=4;
Const int z_Dir_Pin=7;
Const int a_Step_Pin=12;
Const int a_Dir_Pin=13;
Walk//define how much
Const int moveSteps=1600;
//define a time
Const int delayTime=200;
Int Speed=100;
//object definition motor
AccelStepper stepperx (1, x_Step_Pin, x_Dir_Pin);
AccelStepper steppery (1, y_Step_Pin, y_Dir_Pin);
AccelStepper stepperz (1, z_Step_Pin, z_Dir_Pin);
AccelStepper steppera (1, a_Step_Pin, a_Dir_Pin);
Void setup () {
PinMode (x_Step_Pin, the OUTPUT);
PinMode (x_Dir_Pin, the OUTPUT);
PinMode (y_Step_Pin, the OUTPUT);
PinMode (y_Dir_Pin, the OUTPUT);
PinMode (z_Step_Pin, the OUTPUT);
PinMode (z_Dir_Pin, the OUTPUT);
PinMode (a_Step_Pin, the OUTPUT);
PinMode (a_Dir_Pin, the OUTPUT);
PinMode (enablePin, the OUTPUT);
DigitalWrite (enablePin, LOW);
//set the maximum speed and acceleration
Stepperx. SetMaxSpeed (1000);
Stepperx. SetAcceleration (200);
Steppery. SetMaxSpeed (1000);
Steppery. SetAcceleration (200);
Stepperz. SetMaxSpeed (1000);
Stepperz. SetAcceleration (200);
Steppera. SetMaxSpeed (1000);
Steppera. SetAcceleration (200);
}
Void loop () {
MFord ();
MBack ();
MLeft ();
MRight ();
//motor sports
Stepperx. The run ();
Steppery. The run ();
Stepperz. The run ();
Steppera. The run ();
}
Void MFord () {//forward
If (stepperx currentPosition ()==0) {
Stepperx. MoveTo (moveSteps);
}
If (steppery currentPosition ()==0) {
Steppery. MoveTo (- moveSteps);
}
If (stepperz currentPosition ()==0) {
Stepperz. MoveTo (moveSteps);
}
If (steppera currentPosition ()==0) {
Steppera. MoveTo (- moveSteps);
}
return 0;
}
Void MBack () {//backward
If (stepperx currentPosition ()==moveSteps) {
Stepperx. MoveTo (0);
}
If (steppery currentPosition ()==- moveSteps) {
Steppery. MoveTo (0);
}
If (stepperz currentPosition ()==moveSteps) {
Stepperz. MoveTo (0);
}
If (steppera currentPosition ()==- moveSteps) {
Steppera. MoveTo (0);
}
return 0;
}
Void MLeft () {//to the
If (stepperx currentPosition ()==0) {
Stepperx. MoveTo (- moveSteps);
}
If (steppery currentPosition ()==0) {
Steppery. MoveTo (- moveSteps);
}
If (stepperz currentPosition ()==0) {
Stepperz. MoveTo (moveSteps);
}
If (steppera currentPosition ()==0) {
Steppera. MoveTo (moveSteps);
}
return 0;
}
Void MRight () {//to the right
If (stepperx currentPosition ()==- moveSteps) {
Stepperx. MoveTo (0);
}
If (steppery currentPosition ()==- moveSteps) {
Steppery. MoveTo (0);
}
If (stepperz currentPosition ()==moveSteps) {
Stepperz. MoveTo (0);
}
If (steppera currentPosition ()==moveSteps) {
Steppera. MoveTo (0);
}
return 0;
}
}
In addition I still to go how to control the step motor fixed distance feel confused, the principle of stepping motor, calculation formula of the distance I have access to related data, also saw video of some related, but just don't know how to write a program that would like to ask you, how to write a program?