DC Motor Speed Control is different?

Hello,
I am building a small Rc Car atm just for fun, in the most simple way possible. But I found something very interresting and weird. In my main Sketch for the Rc Car, the code for controlling the Motor only works if I do analogWrite(motorPin1, 255) so the max… everything below does not work.

However in a test Sketch it does somehow work down to 180. I will quickly add those two sketches here, so you could look over it.

Rc Car Code

#include <Servo.h>

Servo servo;

int motorPin1 = 9;
int motorPin2 = 10;

int pos = 0;

void setup() {
// put your setup code here, to run once:
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);

servo.attach(11);

Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:

while(Serial.available() == 0);

int val = Serial.read();

if (val == 119)
{
Serial.println(“Forward”);
analogWrite(motorPin1, 255);
analogWrite(motorPin1, 255);

servo.write(90);
}
else if (val == 97)
{
Serial.println(“Left”);
analogWrite(motorPin1, 255);
analogWrite(motorPin1, 255);
servo.write(40);
}
else if ( val == 100)
{
Serial.println(“Right”);
analogWrite(motorPin1, 255);
analogWrite(motorPin1, 255);
servo.write(150);
}
else if ( val == 115)
{
Serial.println(“Stop”);
analogWrite(motorPin1, 0);
analogWrite(motorPin1, 0);
servo.write(90);
}
Serial.println(val);

}

Test Code

int motorPin1 = 9;
int motorPin2 = 10;

void setup() {
// put your setup code here, to run once:
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
analogWrite(motorPin1, 190);
analogWrite(motorPin2, 190);

}

It would be great if someone could help, and tell me what exactly is preventing me from going lower than max with the Rc Car sketch. Since the wiring was kept the same, I highly doubt that it should be a problem with it. The only problem is why one sketch allows the DC Motor Speed to go lower than the other.

Thanks a lot for your time, and also Thanks in advance if you can help me!

-Basil

Read the notes on the Servo library reference page

Oh I see, Pins 9 and 10 are no longer PWM... that explain it >.>

Thanks!

Didn't think that that would actually be a thing.

Thanks alot! and Sorry for the derpy question I guess.

-Basil

if (val == 119)

Two weeks from now, are you going to remember, looking at the code, what to send to make this statement true?

if(val == 'w')

Two weeks from now, are you going to remember, looking at the code, what to send to make this statement true?