I hope this isn’t too late to help.
An Arduino isn’t required for your task.
I have a length of ball screw in a frame, with a stepper motor and its driver, complete with two end switches and a control box wired as this example.
It functions just as you require, an endless to and fro from one end limit to the other with the speed set by the knob.
I use it to test stepper motors and their drivers in an endless soak test.