// defines pins numbers
const int stepPin = 3; /////MOTOR 1 CLOCK
const int dirPin = 2; //// MOTOR 1 DIRECTION
const int stepPin1 = 6; //// MOTOR 2 CLOCK
const int dirPin1 = 7; ///// MOTOR 2 DIRECTION
const int stepPin2 = 6; //// MOTOR 3 CLOCK
const int dirPin2 = 7; //// MOTOR 3 DIRECTION
const int stepPin3 = 6; //// MOTOR 4 CLOCK
const int dirPin3 = 7; //// MOTOR 4 DIRECTION
int sw = A0;
int sw1 = A1;
int sw2 = A2;
int sw3 = A3;
int State=0;
int State1=0;
int State2=0;
int State3=0;
int Button;
int Button1;
int Button2;
int Button3;
void setup() {
// Sets the two pins as Outputs
pinMode(sw,INPUT);
pinMode(sw1,INPUT);
pinMode(sw2,INPUT);
pinMode(sw2,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);
digitalWrite(dirPin,LOW);
stepper();
State=0;
digitalWrite(dirPin1,LOW);
stepper1();
State1=0;
digitalWrite(dirPin2,LOW);
stepper2();
State2=0;
digitalWrite(dirPin3,LOW);
stepper3();
State3=0;
}
void loop() {
Button = digitalRead(sw);
Button1 = digitalRead(sw1);
Button1 = digitalRead(sw2);
Button1 = digitalRead(sw3);
/////////////////////////////////////////////////////////////////////// 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 < 64; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(600);
digitalWrite(stepPin,LOW);
delayMicroseconds(600);
}
}
void stepper1()
{
for(int x = 0; x < 61; x++) {
digitalWrite(stepPin1,HIGH);
delayMicroseconds(600);
digitalWrite(stepPin1,LOW);
delayMicroseconds(600);
}
}
void stepper2()
{
for(int x = 0; x < 61; x++) {
digitalWrite(stepPin2,HIGH);
delayMicroseconds(600);
digitalWrite(stepPin2,LOW);
delayMicroseconds(600);
}
}
void stepper3()
{
for(int x = 0; x < 61; x++) {
digitalWrite(stepPin3,HIGH);
delayMicroseconds(600);
digitalWrite(stepPin3,LOW);
delayMicroseconds(600);
}
}