Sunteți pe pagina 1din 2

// This program runs two stepper motors to control a X-Y Table.

// The input is in the form of the function F(x,y) where x and y relate to the c
arteian cordinate system.
// Comunitaction b/w the Arduino and the Computer software is through the serial
port (USB).
#include <AccelStepper.h>
// X-Axis Motor Pins:
int Xpin1 = 13;
int Xpin2 = 12;
int Xpin3 = 11;
int Xpin4 = 10;
// Y-Axis Motor Pins:
int Ypin1 = 9;
int Ypin2 = 8;
int Ypin3 = 7;
int Ypin4 = 6;
// Define the steppers:
AccelStepper stepperX(4,Xpin1,Xpin2,Xpin3,Xpin4); // 4Pin, pins.
AccelStepper stepperY(4,Ypin1,Ypin2,Ypin3,Ypin4);
void setup(){
Serial.begin(9600); // Begin serial communiation at 9600.
// Set up conditions for X-Axis stepper.
stepperX.setMaxSpeed(100.0); // Sets max speed of stepperX.
stepperX.setAcceleration(25.0); // Sets acceleration, 1.0 is default.
stepperX.setCurrentPosition(0.0);
// Set up conditions for Y-Axis stepper.
stepperY.setMaxSpeed(100.0); // Sets max speed of stepperY.
stepperY.setAcceleration(25.0); // Sets acceleration, 1.0 is default.
stepperY.setCurrentPosition(0.0);
}
void loop(){
char axis;
int pos;
int serIn;
char serInString[2] = {'0','0'};
int i=0;
if (Serial.available()>0) {
while (Serial.available()) {
serIn = Serial.read();
serInString[i] = serIn;
i++;
axis = serInString[0];
int val = serInString[1];
pos = (val - 48);
}
}
Serial.println(pos);
switch(axis){
case 'x':
stepperX.runToNewPosition(pos);
stepperX.run();
break;
case 'y':
stepperY.runToNewPosition(pos);
stepperY.run();
break;
}
}

//*//stepper?.moveTo(Abs pos); // Moves the stepper to a targetPos as set distan


ce from the starting position.
//*//stepper?.move(realative); // Moves the stepper a relative distance from it'
s current position.
//*//stepper?.setMaxSpeed(); // sets max speed.
//*//setpper?.setAcceleration(); // sets acceleration.
//*//stepper?.setSpeed(); // if speed is set = to speed do nothing : if speed is
> maxSpeed set speed = maxSpeed : else speed = speed.
//*//stepper.?setCurrentPosition(); // Sets currentPos = position.
//*//stepper?.runToNewPosition(); //Sets a new target position and then waits ti
ll the stepper has achived it.
//*//stepper?.setMinPulseWidth(); // Sets min pulse width.
//+//stepper?.currentPosition(); // Returns currentPos.
//+//stepper?.targetPosition(); // Returns targetPos.
//+//stepper?.distanceToGo(); // Returns targetPos - currentPos.
//+//stepper?.speed(); // returns current speed.
//-//stepper?.run(); // If targetPos == currentPos return false: returns true if
still running.
//-//stepper?.runToPosition(); // runs to position and waits till position is re
ached.
//-//stepper?.RunSpeedToPosition(); // runs speed to position?
//-//stepper?.runSpeed(); //??

S-ar putea să vă placă și