Controlling speed and position with DC Motor Encoder.

Divide your learning into small parts.

Write a short program to read a limit switch and display Off or On in the Arduino Serial Monitor

Write another short program to control the speed of the motor - first based on a data value in your program and then, perhaps, based on a potentiometer.

Write a short program to detect and count pulses and direction from the encoder and display the data on the Serial Monitor.

You should find lots of online advice about each of these.

There are lots of useful links on the Useful Links Thread.

...R