Controling a servo -Analog pins 8-15 don't work

Hello everybody, this is my first post and my first problem I've run into with my Arduino. =P

I'm trying to control a servo with my Arduino Mega using the servo example included in Arduino 0017. My problem is that when my pot is connected to analog pins 8 though 15, the servo tweaks out and turns all the way to one side. Everything runs perfectly when I have my pot connected to analog pins 0 through 7 so I'm not sure why pins 8-15 don't work.

Does anybody know why analog pins 8-15 don't work?

Here's the example code that I modified. The only thing I changed is the pin for potpin, highligted in yellow.

// Controlling a servo position using a potentiometer (variable resistor) 
// by Michal Rinott

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
 
int potpin = [glow]8[/glow];  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
void loop() 
{ 
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 
}

Many thanks in advance!

Check the pin mapping for the Mega. It maybe that the arduino mega pins 0-7 are ADC pins but 8-15 are used for something else. I think on the schematic the green numbers are the Arduino defalt pins, but it seems that the second bank of ADC pins do not have defualt arduino pins assigned to them.
i.e. The pins 8-15 are not the analog pins you think they are (I think :-?)
Schematic: http://arduino.cc/en/uploads/Main/arduino-mega-schematic.pdf

Edit: Sorry was looking at the wrong header, seems that none of the analog pins are numbered, giving the impression that they are just referenced as ADC0-15.

There is a bug in Arduino IDE ver 17 that prevents analog inputs 8-15 from working on the Mega processor. The problem is not there in version 16 and will be fixed in version 18 due pretty soon. There is a simple patch you can make to one of the library files in version 17 that was posted by Mellis.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1250970792

Lefty

Apparently it is a bug in the IDE 0017, see the thread below for details. Hope it helps you out!
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1250980394
[edit]Man, I just finished replying after I read your post Lefty and I find out that you have beaten me to it![/edit]

Thank you guys so much! The patch works and my servo is running normally now!