Title covered main issue pretty much. Basically I have a separate esp-32 cam that detects events and sends a signal to the arduino to switch the stepper motor direction. (Ignore the distance sensor part, that is the 2nd part of the project I'm working on but I can't proceed because of this issue.) Any tips?
#include <ContinuousStepper.h>
ContinuousStepper<FourWireStepper> stepper;
ContinuousStepper<FourWireStepper> stepper1;
const int trigPin = 7;
const int echoPin = 8;
float duration, distance;
char c;
void setup() {
Serial.begin(115200);
Serial.println("Arduino UART receiver ready");
stepper.begin(10, 12, 11, 13);
stepper1.begin(3, 5, 4, 6);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration*.0343)/2;
Serial.print("Distance: ");
Serial.println(distance);
if (distance < 15) {
}
if (Serial.available()) {
c = Serial.read();
if (c == 'L') {
stepper1.spin(500);
stepper.spin(500);
}
else if (c == 'R') {
}
else if (c == 'F') {
stepper1.spin(-500);
stepper.spin(500);
}
else if (c == 'S') {
stepper1.spin(500);
stepper.spin(500);
}
}
stepper.loop();
stepper1.loop();
}