Combining two working sketches and they don't work together...

So on the first attached script is a sketch which runs motors on a Motor Shield: Motor Shield - LinkSprite Playgound

The second sketch is an attempt to add in servo functions.

The kicker is the Rover_Motors.ino runs the motors as I'd like them to, and I can control them on the serial port, and the Rover_Servos_n_Motors.ino controls the servos as I would like them to.

BUT The motors do not function in the sketch with the servos. As I'm extremely new to arduino code I was wondering if anyone spots and reasons why the motors will not drive when the servo code is inserted into the sketch?

Thanks guys!

Rovor_Motors.ino (4.26 KB)

Rover_Servos_n_Motors.ino (4.63 KB)

On boards other than the Mega, use of the servo library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins. That is most likely the root of your problem.

You will need to use pins other than 9 and 10 for speed control of the motors or use an alternative servo library that does not use the same timer as PWM. There is a servo library called ServoTimer2 which does not interfere with PWM on pins 9 and 10.

Incidentally, why have you got the pinMode() commands in loop() ? The pin mode only needs to be set once in setup() and what is the purpose of while(1) when the loop() function does as its name suggests and loops ?

Wow thanks for the quick response! I will look into this and hopefully post back tomorrow if it was a success or failure haha.

The PinMode in loop() I originally had it only set it once, but I tried placing it in loop() just to see if it made a difference in getting the motors working (with little to no hope I was just out of ideas at that point lol). I just forgot to put it back. Thanks for the information on that as well though! I feel like such a novice at all this I really appreciate the help!

It is a very common problem and I nearly didn't bother to download your program but when I did I spotted the other things that I commented on, including the while(1)