Hello, Everyone
I'm completely new to the Arduino platform and without any experience of coding at all. I'm trying to build a dual focus system for my camera rig. I want to focus two lenses at the same time to the same focal length. Due to the different focus ring throw distance on individual lenses, the speed at which each lens needs to focus has to be variable. I hope to build a prototype using two stepper motors to see whether the concept works.
I found a simple sketch (I will post the schematic and sketch below) to drive one stepper motor that uses an Arduino UNO/ L293 IC/ Potentiometer to control speed/ 2 switches + resistors for forward/reverse direction/ 4 LEDS + resistors to indicate motor phase. The stepper is a 5V, 4 phase, 28BYJ-48 motor. It all works well. I would now like to add a second stepper motor to mirror exactly this combination. I have purchased the extra parts necessary and have already wired them up using pins 4 and 5 as switch INPUTs, pins 6, 7, 8 and 9 for the second L293 chip, and A1 for the second potentiometer. I hope this is correct.
I am now struggling with the coding aspect. I naively hoped it was as simple as assigning the corresponding names/numbers to each motor/int/ pinMode lines of code. Then by duplicating the code within the void loop and assigning the respective name and numbers to their anologRead/ digitalRead/ set/ setSpeed commands lines and it would work. When I do this, I get an “expected-unqualified error before 'if'” statement in the duplicated portion of the code. I will only post the original code here as my effort at coding would probably serve more to confuse than contribute..
If anyone is able to help with the coding, it would be greatly appreciated. Thanks in advance to everyone.
Original Code:
#include <Stepper.h>
int forward = 2;
int reverse = 3;
Stepper motor(200, 10,11,12,13);
void setup() {
pinMode(forward,INPUT);
pinMode(reverse,INPUT);
}
void loop() {
int Speed = analogRead(A0);
int RPM = map(Speed, 0, 1023, 0, 100);
int f = digitalRead(forward);
int r = digitalRead(reverse);
if(f == 1 && r == 0 && RPM > 1){
motor.step(1);
motor.setSpeed(RPM);
delay(.01);
}
if(r == 1 && f== 0 && RPM > 1){
motor.step(-1);
motor.setSpeed(RPM);
delay(.01);
}
delay(5);
}]