Controlling motors and LED's

I need some guidence on controlling a DC motor with PWM. I have had it plugged in and working I just have one question. How can I get the PWM to ramp up from 0 to 255 really slow. And then stay full until it sees a switch on a input and then it slows down at the same rate.

What I am shooting for is turning a motor on with the driver and want it to come up really slow until I tell it to shut down. I have code running it up but it wan't stay there. It keeps running over and over. I need it to stay at Full Speed until I tell it to stop. It would be like having a soft start up and slow down.