Need Help Controlling DC Motor with POT

I am a mechanical engineer introducing myself to electrical circuitry with the Inventor's kit from SparkFun. I finished section 12 where you can turn a motor to two different speeds using speeds from 0-255 (0-5v) and time delay in milliseconds.

I decided to try and use an analog in from the supplied POT to make a speed control using the analog read (0-1023) as a multiplier. If I use the analog read as a time delay in milliseconds (not shown below) it responds to my inputs at the POT. However, using the code I've provided I can't get the motor to spin during that 1000ms of control. It does spin on the other 1000ms coded. Any critical errors with my code below?

Thanks in advance, just getting started so please forgive any newbie mistakes.

// We'll be controlling the motor from pin 9.
// This must be one of the PWM-capable pins.

int sensorPin = 0; // The potentiometer is connected to
// analog pin 0int sensorValue;

int motorPin = 9;

void setup()
{
// Set up the motor pin to be an output:

pinMode(motorPin, OUTPUT);

// Set up the serial port:

Serial.begin(9600);
}

void loop()

{

motorOnThenOffWithSpeed();

}

void motorOnThenOffWithSpeed()
{
const int scale = 1023;
int sensorValue = analogRead(sensorPin);
int speedFactor = sensorValue/scale;
int Speed1 = speedFactor*255; // between 0 (stopped) and 255 (full speed)
int Time1 = 1000; // milliseconds for speed 1

int Speed2 = 150; // between 0 (stopped) and 255 (full speed)
int Time2 = 1000; // milliseconds to turn the motor off

analogWrite(motorPin, Speed1); // turns the motor On
delay(Time1); // delay for onTime milliseconds
analogWrite(motorPin, Speed2); // turns the motor Off
delay(Time2); // delay for offTime milliseconds
}

 const int scale = 1023;
  int sensorValue = analogRead(sensorPin);
  int speedFactor = sensorValue/scale;

No, that's mostly just going to set it to zero. Integer division truncates in C, so only if the
result of analogRead() is at its maximum will speedFactor be greater than 0.

Always multiply first, then divide, and use enough bits (ie a long):

  analogWrite (motorPin, (255L * analogRead (sensorPin)) / 1023) ;

Or the commonly used map() function:

  analogWrite (motorPin, map (analogRead (sensorPin), 0, 1023, 0, 255)) ;

Put Serial.prints between each line of your function and watch how the values change. There might be some math that is not working like you think.

Most people would just use the map() function to translate an analog read to PWM.

Thank you both for the response, the map function is working beautifully!

You must pay attention to data types. data-types-in-arduino tutorial