#include <AccelStepper.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
#define MAX_POSITION 0x7FFFFFFF // maximum of position
#define DEG_PER_STEP 1.8
#define STEP_PER_REVOLUTION (360 / DEG_PER_STEP)
//AccelStepper Xaxis(1, 2, 5); // pin 2 = step, pin 5 = direction
//AccelStepper Yaxis(1, 3, 6); // pin 3 = step, pin 6 = direction
AccelStepper Xaxis(1, 18, 5); // pin 3 = step, pin 6 = direction
AccelStepper Yaxis(1, 16, 4); // pin 4 = step, pin 7 = direction
long Park = STEP_PER_REVOLUTION;
long go = MAX_POSITION;
void setup() {
Xaxis.setAcceleration(100.0);
Xaxis.setSpeed(100);
Xaxis.setCurrentPosition(0);
go = -1 * go; // cambia la direccion a CCW (para buscar el home)
Xaxis.moveTo(go); // mueve el motor hasta el infinito y mas alla (home)
}
void loop() {
if (Xaxis.distanceToGo() != 0) {
Xaxis.setCurrentPosition(0); // position to 0
go = -1 * go; // cambia de nuevo a CW
Xaxis.moveTo(Park); // move motor one revolution
}
Xaxis.run();
}
/**#include <AccelStepper.h>
#include <ezButton.h>
#define MAX_POSITION 0x7FFFFFFF // maximum of position
#define DEG_PER_STEP 1.8
#define STEP_PER_REVOLUTION (360 / DEG_PER_STEP)
ezButton homeS(A1);
ezButton limitS(A0);
ezButton start(8);
AccelStepper stepper(AccelStepper::FULL2WIRE, 47, 46);
long Park = STEP_PER_REVOLUTION;
long go = MAX_POSITION;
void setup() {
Serial.begin(9600);
homeS.setDebounceTime(50);
limitS.setDebounceTime(50);
start.setDebounceTime(50);
stepper.setAcceleration(100.0);
stepper.setSpeed(100);
stepper.setCurrentPosition(0);
go = -1 * go; // cambia la direccion a CCW (para buscar el home)
stepper.moveTo(go); // mueve el motor hasta el infinito y mas alla (home)
}
void loop() {
homeS.loop(); // loop para botones y switchs
limitS.loop();
start.loop();
///////////////////////////////////////////////////////////
if (homeS.isPressed())
if (stepper.distanceToGo() != 0) {
stepper.setCurrentPosition(0); // position to 0
go = -1 * go; // cambia de nuevo a CW
stepper.moveTo(Park); // move motor one revolution
}
if (limitS.isPressed())
if (stepper.distanceToGo() != 0) {
stepper.setCurrentPosition(0); // reset position to 0
go = -1 * go; // reverse direction
stepper.moveTo(go);
}
if (start.isPressed())
stepper.moveTo(go);
//////////////////////////////////////////////////////////
stepper.run(); // MUST be called as frequently as possible
}**/