/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#include <Servo.h>
Servo MYservos[2];
const byte servoPins[] = {9,6};
int potpin = 0; // analog pin used to connect the potentiometer
int potpin2 = 1; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int val2;
void setup() {
for(int n = 0; n < 2; n++) {
MYservos[n].attach(servoPins[n]);
}
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val2 = analogRead(potpin2);
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
val2 = map(val2, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
MYservos[0].write(val); // sets the servo position according to the scaled value
MYservos[1].write(val2);
delay(15); // waits for the servo to get there
}