#define dir1 2 //Motor 1
#define step1 3
#define stepsPerRevolution1 200
#define dir2 4 //Motor 2 (Cutter)
#define step2 5
#define stepsPerRevolution2 200
const int sw = 7;
int swi;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(dir1, OUTPUT); //Motor 1
pinMode(step1, OUTPUT);
pinMode(dir2, OUTPUT); //Motor 2
pinMode(step2, OUTPUT);
pinMode(sw, INPUT); //Switch
}
void loop() {
// put your main code here, to run repeatedly:
int swi = digitalRead(sw);
if(swi == 0){
// Set the spinning direction clockwise:
digitalWrite(dir1, HIGH);
Serial.println("Motor 1 - Clockwise");
// Spin the stepper motor 1 revolution quickly:
for (int i = 0; i < stepsPerRevolution1; i++) {
// These four lines result in 1 step:
digitalWrite(step1, HIGH);
Serial.println("Motor 1 - Running");
delayMicroseconds(1000);
digitalWrite(step1, LOW);
//delayMicroseconds(1000);
}
// Set the spinning direction clockwise:
digitalWrite(dir2, HIGH);
Serial.println("Motor 2 - Clockwise");
// Spin the stepper motor 2 revolution quickly:
for (int i = 0; i < stepsPerRevolution2; i++) {
// These four lines result in 1 step:
digitalWrite(step2, HIGH);
Serial.println("Motor 2 - Running");
delayMicroseconds(1000);
//digitalWrite(step2, LOW);
//delayMicroseconds(1000);
}
}
if(swi == 1){
// Set the spinning direction counterclockwise:
Serial.println("Switch ON");
digitalWrite(dir2, LOW);
// Spin the stepper motor 2 revolution quickly:
for (int i = 0; i < stepsPerRevolution2; i++) {
// These four lines result in 1 step:
digitalWrite(step2, HIGH);
Serial.println("Motor 2 - Running");
delayMicroseconds(1000);
//digitalWrite(step2, LOW);
//delayMicroseconds(1000);
}
}
}