hello, this is only my second project and I need a little bit of help im not looking to make beautiful code just code that works for what I need it to do.
I want to use 2 linear sliders each with there own stepper motor and pot, the plan is to have pre set position that the sliders have to move to in order AKA from (0,0) to (100,200) to (300,100) to (0,0) -- I used arrays to do this...
I believe I am at a point where the code will work however I am not 100% sure.
so I am just looking for some feedback.
thanks for the help
#include <Stepper.h>
// button //
const int buttonPin = 1;
int buttonState = 0;
// Platform //
const int SPR = 200; // steps Per Revolation
const int Pitch = 5; // distance between teeth
const int MS = 4; // mirco steps per step
float SPU = ((SPR*MS) / Pitch); // steps Per Unit mm
// X diretion motor //
const int in1Pin = 2; //pin step up for motor 1
const int in2Pin = 3;
const int in3Pin = 4;
const int in4Pin = 5;
Stepper myStepperX(SPR, in1Pin, in2Pin, in3Pin, in4Pin);
// Y direction motor //
const int in5Pin = 6; //pin set up for motor 2
const int in6Pin = 7;
const int in7Pin = 8;
const int in8Pin = 9;
Stepper myStepperY(SPR, in5Pin, in6Pin, in7Pin, in8Pin);
// counters//
int countX = 0; // starts countX at 0
int countY = 0; // starts countY at 0
//Arrays//
int myArrayXH[] = {120, 226, 423, 426, 602, 615, 779, 792}; // analog Values for X Direction
int myArrayX[] = {116, 222, 419, 422, 598, 611, 775, 788};
int myArrayXL[] = {112, 218, 415, 418, 594, 607, 771, 784};
int myArrayYH[] = {822, 536, 209};
int myArrayY[] = {818, 532, 205}; // analog Values of Y Direction
int myArrayYL[] = {814, 528, 201};
//smoothing DATA//
const int NumReadings = 20;
int total = 0;
int average = 0;
// sensors //
int sensorReadingx = 0; //analogRead(A0);
int sensorReadingy = 0; //analogRead(A1);
//Setup//
void setup()
{
Serial.begin(9600);
Serial.println(MS);
Serial.println(Pitch);
Serial.println(SPU);
Serial.println(countX);
Serial.println(myArrayX[countX]);
Serial.println(countY);
Serial.println(myArrayY[countY]);
Serial.println("Waiting for Input");
delay(1000);
START:
if (Serial.available() > 0)
{
buttonState = HIGH;
} else goto START;
Serial.println("Start");
if (buttonState == HIGH)
{
CALABRATION();
delay(50);
}
}
void YForwards()
{
int MotorDirection = 1;
int motorSpeed = 200;
int STEPS = (SPU * MotorDirection);
myStepperY.setSpeed(motorSpeed);
myStepperY.step(STEPS);
delay(500);
}
void YBackWards()
{
int MotorDirection = -1;
int motorSpeed = 200;
int STEPS = (SPU * MotorDirection);
myStepperY.setSpeed(motorSpeed);
myStepperY.step(STEPS);
delay(500);
}
void YSTOP()
{
int MotorDirection = 0;
int motorSpeed = 0;
int STEPS = (SPU * MotorDirection);
myStepperY.setSpeed(motorSpeed);
myStepperY.step(STEPS);
delay(500);
}
void XForwards()
{
int MotorDirection = 1;
int motorSpeed = 200;
int STEPS = (SPU * MotorDirection);
myStepperX.setSpeed(motorSpeed);
myStepperX.step(STEPS);
delay(500);
}
void XBackWards()
{
int MotorDirection = -1;
int motorSpeed = 200;
int STEPS = (SPU * MotorDirection);
myStepperX.setSpeed(motorSpeed);
myStepperX.step(STEPS);
delay(500);
}
void XSTOP()
{
int MotorDirection = 0;
int motorSpeed = 0;
int STEPSCAL = (SPU * MotorDirection);
myStepperX.setSpeed(motorSpeed);
myStepperX.step(STEPSCAL);
delay(500);
}