Running a DC motor with PWM

loop()
for (int x=1; x<256;x++)
{
// look at the digital write code & place here
// add some delay for the motor to move
}

Place the above in setup()
In loop() look at a digital i/p switch use an 'if' statement, then run a 'for' loop to slow down your motor.