How would I go about doing this?
Understand what control algorithm you want to implement i.e. whether the motor speed is to be controlled by feedback from some sensor, simply by elapsed time, or some other criteria.
Set up the hardware to power and control the motor and write a simple sketch that carries out a simple sequence of motor actions to confirm you know how to control the motor.
Set up the hardware for any sensors you need and write a simple sketch that demonstrates you're capable of reading data from those sensors and get the results you expect.
Write the code which implements your chosen control algorithm to control the motor based on whatever inputs it needs.
Test, fix, repeat as necessary until it is good enough for your needs.