I need help with the code on how to control the speed of a motor.
We can't help with code we cannot see.
Fine. So first tell us what sort of motor (a link would be useful) and then show us what you've tried and what happened when you tried it.
People round here are really good at helping you get your code right, but you have to make a start.