/*
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 myservo1; // create servo object to control a servo
Servo myservo2;
// analog pin used to connect the potentiometer
int val1;
int val2; // variable to read the value from the analog pin
void setup() {
myservo1.attach(9);
myservo2.attach(11);
pinMode(A0, INPUT);
pinMode(4, OUTPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}
void loop() {
val1 = analogRead(A0);
val2 = analogRead(A1);
// Serial.println(val);
val1 = map(val1,0,1023,0,180);
val2 = map(val2,0,1023,0,180);
//Serial.println(val);
digitalWrite(4 ,digitalRead(A2) ) ;
myservo1.write(val1);
myservo2.write(val2);
// sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}