#include "AccelStepper.h"
#include <MultiStepper.h>
#define pul1 10
#define dir1 2
#define pul2 3
#define dir2 4
#define pul3 5
#define dir3 6
#define stepsPerRevolution 1600
long gotoposition[2];
AccelStepper stepper2(1, 3, 4);
AccelStepper stepper3(1, 5, 6);
MultiStepper steppers;
#define LED_PIN1 8
#define LED_PIN2 9
#define LED_PIN3 13
#define BUTTON_PIN 7
void setup1() {
pinMode(LED_PIN1, OUTPUT);
pinMode(LED_PIN2, OUTPUT);
pinMode(LED_PIN3, OUTPUT);
pinMode(BUTTON_PIN, INPUT);
pinMode(pul1, OUTPUT);
pinMode(dir1, OUTPUT);
pinMode(pul2, OUTPUT);
pinMode(dir2, OUTPUT);
pinMode(pul3, OUTPUT);
pinMode(dir3, OUTPUT);
//stepper2.setMaxSpeed(1000);
//stepper3.setMaxSpeed(1000);
}
void setup()
{
digitalWrite(LED_PIN1, HIGH);
{
steppers.addStepper(stepper2);
steppers.addStepper(stepper3);
stepper2.setMaxSpeed(200);
stepper3.setMaxSpeed(200);
stepper2.setAcceleration(10);
stepper2.moveTo( -20000 );
while( digitalRead( BUTTON_PIN ) == LOW ) stepper2.run();
stepper2.setCurrentPosition( 0 );
// start normal move}
}
{
if (digitalRead(BUTTON_PIN) == HIGH) {
digitalWrite(LED_PIN3, HIGH);
digitalWrite(dir2, HIGH); //pasaka HIGH, paubos LOW
for (int i=0; i <1600; i++) {
digitalWrite(pul2, HIGH);
delayMicroseconds(200);
digitalWrite(pul2, LOW);
delayMicroseconds(200);}
delay(1000);}
else {
digitalWrite(LED_PIN3, LOW); }
}
{
digitalWrite(dir1, LOW);
for (int i=0; i <400; i++) {
digitalWrite(pul1, HIGH);
delayMicroseconds(200);
digitalWrite(pul1, LOW);
delayMicroseconds(200);}
}
{
stepper2.setCurrentPosition(0);
stepper3.setCurrentPosition(0);
digitalWrite(dir2, LOW); //pasaka HIGH, paubos LOW
for (int i=0; i <1500; i++) {
digitalWrite(pul2, HIGH);
delayMicroseconds(200);
digitalWrite(pul2, LOW);
delayMicroseconds(200);}
delay(1000);
}
long gotoposition[2];
gotoposition[0] = -800; //steper2, 800(half.rev) = 1.03mm linear movement
gotoposition[1] = 160000; //stepper3
steppers.moveTo(gotoposition);
steppers.runSpeedToPosition();
delay(500);
{
digitalWrite(dir3, LOW); //CCW
for (int i=0; i < 3200; i++) {
digitalWrite(pul3, HIGH);
delayMicroseconds(500);
digitalWrite(pul3, LOW);
delayMicroseconds(500);
}
}
delay(500);
{
digitalWrite(dir2, HIGH);
for (int i=0; i < 1900; i++) {
digitalWrite(pul2, HIGH);
delayMicroseconds(500);
digitalWrite(pul2, LOW);
delayMicroseconds(500);
}
}
delay(3000);
}
void loop()
{}