#include <AccelStepper.h>
#include <MultiStepper.h>
/////////////////////////////////////////////////////////////////
AccelStepper stepper1(AccelStepper::DRIVER, 2, 3);
AccelStepper stepper2(AccelStepper::DRIVER, 4, 5);
AccelStepper stepper3(AccelStepper::DRIVER, 6, 7);
MultiStepper steppers;
//string recibirdatos;
String vectorCaracteres;
String subStr1;
long Position;
long vel;
void setup() {
Serial.begin(9600);
Serial.println("");
// Configure each stepper
stepper1.setMaxSpeed(1000);
stepper2.setMaxSpeed(1000);
stepper3.setMaxSpeed(1000);
// Then give them to MultiStepper to manage
steppers.addStepper(stepper1);
steppers.addStepper(stepper2);
steppers.addStepper(stepper3);
stepper1.setAcceleration(50);
stepper2.setAcceleration(50);
stepper3.setAcceleration(50);
}
void loop() {
if(Serial.available()){
char CharEntrada = Serial.read(); //Leer un byte del puerto serial
vectorCaracteres += CharEntrada; //Agregar el char anterior al string
if (CharEntrada == '\n') { //Si se detecta un fin de linea
//Serial.println(vectorCaracteres);
int i = vectorCaracteres.indexOf("X");
int j = vectorCaracteres.indexOf("Y");
int k = vectorCaracteres.indexOf("Z");
int inc=vectorCaracteres.length();
//Serial.println(i);
//Serial.println(j);
//Serial.println(k);
//Serial.println((inc-1));
String subStr1 = vectorCaracteres.substring(i+1,j);
String subStr2 = vectorCaracteres.substring(j+1,k);
String subStr3 = vectorCaracteres.substring(k+1,inc);
//Serial.print("x=");
//Serial.println(subStr1);
//Serial.print("y=");
//Serial.println(subStr2);
//Serial.print("z=");
//Serial.println(subStr3);
int numX = subStr1.toInt();
int numY = subStr2.toInt();
int numZ = subStr3.toInt();
///////////////////////////////////////////////////////////7
long positions[3]; // Array of desired stepper positions
positions[0] = numX;
positions[1] = numY;
positions[2] = numZ;
steppers.moveTo(positions);
delay(1000);
vectorCaracteres = "";
}
}
//stepper1.setAcceleration(50);
//stepper2.setAcceleration(50);
//stepper3.setAcceleration(50);
//Position=stepper1.currentPosition();
//vel=stepper1.speed();
//Serial.println(Position);
//Serial.println(vel);
//stepper1.run();
steppers.runSpeedToPosition(); // Blocks until all are in position
//int inc=0;
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
drv1:ENABLE
drv1:MS1
drv1:MS2
drv1:MS3
drv1:RESET
drv1:SLEEP
drv1:STEP
drv1:DIR
drv1:GND.1
drv1:VDD
drv1:1B
drv1:1A
drv1:2A
drv1:2B
drv1:GND.2
drv1:VMOT
drv2:ENABLE
drv2:MS1
drv2:MS2
drv2:MS3
drv2:RESET
drv2:SLEEP
drv2:STEP
drv2:DIR
drv2:GND.1
drv2:VDD
drv2:1B
drv2:1A
drv2:2A
drv2:2B
drv2:GND.2
drv2:VMOT
drv3:ENABLE
drv3:MS1
drv3:MS2
drv3:MS3
drv3:RESET
drv3:SLEEP
drv3:STEP
drv3:DIR
drv3:GND.1
drv3:VDD
drv3:1B
drv3:1A
drv3:2A
drv3:2B
drv3:GND.2
drv3:VMOT
stepper1:A-
stepper1:A+
stepper1:B+
stepper1:B-
stepper2:A-
stepper2:A+
stepper2:B+
stepper2:B-
stepper3:A-
stepper3:A+
stepper3:B+
stepper3:B-