Documente Academic
Documente Profesional
Documente Cultură
// 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;
}
}