Controlling slots cars with a mosfet

the very basic sketch i have been using for testing is here, I've been altering the output to pin 9 from 0 to 255. Should I be using a digitalwrite?
I'm not sure about the diode but I thought the module dealt with that?

void setup() {
pinMode(9, OUTPUT);
analogWrite(9, 0);
}

void loop(){}