How to control 2 motors operate in opposite direction simultaneously.

I'm intend to write the program that will control 2 stepper motor run in opposite diretion simultaneously by using AccelStepper function as below:

AccelStepper (void(*forward)(), void(*backward)())

but im confusing if i can assign stepper A and B in the above command line.
and im facing the problem of how should i write according to this syntax.

please kindly reply me^^ Thank You

Three possibilities

The easy one if that matches your use case: If your 2 motors are always in sync but need to run in opposite direction (like 2 motors facing each other with a time belt in between) then just wire them together but exchange polarities of the wires so that when one is turning in the positive direction, the other one is turning in the negative one.

Using the library:

If you have 2 motors you will have to have 2 instances of the class AccelStepper, one for each motor.

There are 2 constructors for that class

AccelStepper (uint8_t interface=AccelStepper::FULL4WIRE, uint8_t pin1=2, uint8_t pin2=3, uint8_t pin3=4, uint8_t pin4=5, bool enable=true);

Or

AccelStepper (void(*forward)(), void(*backward)());

Are you sure you want to use the second one?

If so just provide 4 different functions doing what fwd and bwd should be for each motor

if you think those functions should be the same, then inverse the order for the second motor

The first instance could be initialized with (void(*forward)(), void(*backward)()) and the second with AccelStepper (void(*backward)(), void(*forward)());

Third option is to use the 1st constructor method and provide all your pins etc and drive the way you want.

thank you for your help and finally understand what those syntax means.....