// defines pins numbers
#include <AccelStepper.h>
#include <MultiStepper.h>
#include <Bounce2.h>
#include "Arduino.h"
const int stepPin = 3; /////MOTOR 1 CLOCK
const int dirPin = 2; //// MOTOR 1 DIRECTION
const int stepPin1 = 5; //// MOTOR 2 CLOCK
const int dirPin1 = 4; ///// MOTOR 2 DIRECTION
const int stepPin2 = 6; //// MOTOR 3 CLOCK
const int dirPin2 = 7; //// MOTOR 3 DIRECTION
const int stepPin3 = 9; //// MOTOR 4 CLOCK
const int dirPin3 = 8; //// MOTOR 4 DIRECTION
const int stepPin4 = 11; //// MOTOR 5 CLOCK
const int dirPin4 = 10; //// MOTOR 5 DIRECTION
int sw = A0;//////switch 1
int sw1 = A1;/////switch 2
int sw2 = A2;//// switch 3
int sw3 = A3;//// switch 4
int sw4 = A4;//// switch 5
int sw_spare;
int State=0;
int State1=0;
int State2=0;
int State3=0;
int State4=0;
int Button;
int Button1;
int Button2;
int Button3;
int Button4;
void setup() {
// Sets the two pins as Outputs
pinMode(sw,INPUT);
pinMode(sw1,INPUT);
pinMode(sw2,INPUT);
pinMode(sw3,INPUT);
pinMode(sw4,INPUT);
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(stepPin1,OUTPUT);
pinMode(dirPin1,OUTPUT);
pinMode(stepPin2,OUTPUT);
pinMode(dirPin2,OUTPUT);
pinMode(stepPin3,OUTPUT);
pinMode(dirPin3,OUTPUT);
pinMode(stepPin4,OUTPUT);
pinMode(dirPin4,OUTPUT);
digitalWrite(dirPin,LOW);
stepper();
State=0;
digitalWrite(dirPin1,LOW);
stepper1();
State1=0;
digitalWrite(dirPin2,LOW);
stepper2();
State2=0;
digitalWrite(dirPin3,LOW);
stepper3();
State3=0;
digitalWrite(dirPin4,LOW);
stepper3();
State4=0;
}
void loop() {
Button = digitalRead(sw);
Button1 = digitalRead(sw1);
Button2 = digitalRead(sw2);
Button3 = digitalRead(sw3);
Button4 = digitalRead(sw4);
/////////////////////////////////////////////////////////////////////// MOTOR 1
if(Button==LOW && State==0){
digitalWrite(dirPin,HIGH);
stepper();
State=1;
}
if(Button==HIGH && State==1){
digitalWrite(dirPin,LOW);
stepper();
State=0;
}
/////////////////////////////////////////////////////////////// MOTOR 2
if(Button1==LOW && State1==0){
digitalWrite(dirPin1,HIGH);
stepper1();
State1=1;
}
if(Button1==HIGH && State1==1){
digitalWrite(dirPin1,LOW);
stepper1();
State1=0;
}
///////////////////////////////////////////////////////////MOTOR 3
if(Button2==LOW && State2==0){
digitalWrite(dirPin2,HIGH);
stepper2();
State2=1;
}
if(Button2==HIGH && State2==1){
digitalWrite(dirPin2,LOW);
stepper2();
State2=0;
}
/////////////////////////////////////////////////////////// MOTOR 4
if(Button3==LOW && State3==0){
digitalWrite(dirPin3,HIGH);
stepper3();
State3=1;
}
if(Button3==HIGH && State3==1){
digitalWrite(dirPin3,LOW);
stepper3();
State3=0;
}
}
////////////////////////////////////////////////////////// STEPPER CONTROL
void stepper()
{
for(int x = 0; x < 70; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(400);
digitalWrite(stepPin,LOW);
delayMicroseconds(400);
}
}
void stepper1()
{
for(int x = 0; x < 70; x++) {
digitalWrite(stepPin1,HIGH);
delayMicroseconds(400);
digitalWrite(stepPin1,LOW);
delayMicroseconds(400);
}
}
void stepper2()
{
for(int x = 0; x < 70; x++) {
digitalWrite(stepPin2,HIGH);
delayMicroseconds(400);
digitalWrite(stepPin2,LOW);
delayMicroseconds(400);
}
}
void stepper3()
{
for(int x = -10; x < -30; x++) {
digitalWrite(stepPin3,HIGH);
delayMicroseconds(200);
digitalWrite(stepPin3,LOW);
delayMicroseconds(200);
}
}