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!