Dear all,
I would like to rotate two stepper motors at a same time and I should able to stop or start either motor. How would I communicate with Arduino UNO R3 to resolve this issue. I pest my code as below. Please kindly help.
----------------------------------------------------Program---------------------------------------------------------------------------------------------------
#include <Stepper.h>
#define command_clockwise 'a'
#define command_anticlockwise 'd'
#define command_upword 'w'
#define command_downword 's'
#define command_azim_stop 'x'
#define command_elvn_stop 'y'
#define command_stop_antanna ' '
int stepsInRev = 200;
int num_of_steps = 1;
Stepper myStepper1(stepsInRev, 4, 5, 6, 7);
Stepper myStepper2(stepsInRev, 8, 9, 10, 11);
char lastCall = ' ';
void clockwiseStep(int steps){
Serial.println("clockwise");
// step one step each clockwise
myStepper1.step(1);
delay(10);
}
void anticlockwiseStep(int steps){
Serial.println("anticlockwise");
// step one step each anticlockwise
myStepper1.step(-1);
delay(10);
}
void m1Stop(){
Serial.println("stop");
//motor-1 stop
PORTD = B00000000; //sets all of the pins 0 to 7 as LOW to power off stepper1
}
void upwordStep(int steps){
Serial.println("upword");
myStepper2.step(1);
delay(10);
}
void downwordStep(int steps){
Serial.println("downword");
// step one step each backward
myStepper2.step(-1);
delay(10);
}
void m2Stop(){
Serial.println("stop");
//motor-2 stop
PORTB = B00000000; //sets all of the pins 8 to 13 as LOW to power off stepper1
}
void allStop(){
Serial.println("stop");
// steppers stop
PORTD = B00000000; //sets all of the pins 0 to 7 as LOW to power off stepper1
PORTB = B00000000; //sets all of the pins 8 to 13 as LOW to power off stepper2
}
void setup() {
Serial.begin(9600);//start the bluetooth serial port - send and recieve at 9600 baud
// set the speed at 60 rpm:
myStepper1.setSpeed(60);
myStepper2.setSpeed(60);
}
void loop() {
if(Serial.available()) {
char data = (char) Serial.read();
switch(data) {
case command_clockwise:
clockwiseStep (num_of_steps);
break;
case command_anticlockwise:
anticlockwiseStep (num_of_steps);
break;
case command_upword:
upwordStep (num_of_steps);
break;
case command_downword:
downwordStep (num_of_steps);
break;
case command_azim_stop:
m1Stop();
break;
case command_elvn_stop:
m2Stop();
break;
case command_stop_antanna:
allStop();
break;
}
lastCall = data;
}
else{
char data = lastCall;
switch(data) {
case command_clockwise:
clockwiseStep (num_of_steps);
break;
case command_anticlockwise:
anticlockwiseStep (num_of_steps);
break;
case command_upword:
upwordStep (num_of_steps);
break;
case command_downword:
downwordStep (num_of_steps);
break;
case command_azim_stop:
m1Stop();
break;
case command_elvn_stop:
m2Stop();
break;
case command_stop_antanna:
allStop();
break;
}
lastCall = data;
}
}
---------------------------------------------------Program End------------------------------------------------------------------------
Here only one loop is going to execute at a time how would I execute two loops at a time to start and stop either of stepper motor.
I'm beginner with Arduino and C++ .
Please kindly help.
I'm very much thankful to you.