53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
int stepCounter;
|
|
int steps = 2000;
|
|
|
|
#define X_STEP_PIN 54
|
|
#define X_DIR_PIN 55
|
|
#define X_EN_PIN 38
|
|
#define X_CS_PIN 53 // EXP2_07_PIN
|
|
#define X_LIMIT 3 // X_MIN_PIN
|
|
|
|
|
|
int x_steps_mm = 80;
|
|
int y_steps_mm = 400;
|
|
int z_steps_mm = 400;
|
|
int p_steps_mm = 157.5;
|
|
|
|
|
|
// variables to hold location data
|
|
double locX_in_mm;
|
|
double locY_in_mm;
|
|
double locZ_in_mm;
|
|
double locP_in_mm;
|
|
|
|
int locX_in_steps;
|
|
int locY_in_steps;
|
|
int locZ_in_steps;
|
|
int locP_in_steps;
|
|
|
|
|
|
#include <AccelStepper.h>
|
|
#define motorInterfaceType 1
|
|
|
|
|
|
AccelStepper stepper = AccelStepper(motorInterfaceType, X_STEP_PIN, X_DIR_PIN);
|
|
|
|
void setup() {
|
|
// Set the maximum speed and acceleration:
|
|
stepper.setMaxSpeed(1000);
|
|
stepper.setAcceleration(300);
|
|
pinMode(X_EN_PIN, OUTPUT); // Enable
|
|
digitalWrite(X_EN_PIN,LOW);
|
|
}
|
|
void loop() {
|
|
// Set the target position:
|
|
stepper.moveTo(600);
|
|
// Run to target position with set speed and acceleration/deceleration:
|
|
stepper.runToPosition();
|
|
delay(1000);
|
|
// Move back to zero:
|
|
stepper.moveTo(0);
|
|
stepper.runToPosition();
|
|
delay(1000);
|
|
}
|