/*
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;
Servo myservo2; // create servo object to control a servo
int potpin1 = 0;
int potpin2 = 1;
int val1; // analog pin used to connect the potentiometer
int val2;
int pin2 = 2;
int pin3 = 3;
int pin4 = 4; // variable to read the value from the analog pin
void setup() {
myservo1.attach(9);
myservo2.attach(10);
pinMode (2,OUTPUT );
pinMode (3,OUTPUT);
pinMode (4,OUTPUT ); // attaches the servo on pin 9 to the servo object
}
void loop() {
val1 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val1 = map(val1, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo1.write(val1); // sets the servo position according to the scaled value
delay(15);
val2 = analogRead(potpin2 );
val2 = map(val2, 0, 1023, 0, 180);
myservo2.write(val2);
delay(15);
digitalWrite (2,HIGH);
delay(val1);
digitalWrite (2,LOW );
delay(val1);
digitalWrite (3, HIGH );
delay (100);
digitalWrite (3, LOW );
delay (100);
digitalWrite (4, HIGH );
delay (100);
digitalWrite (4,HIGH );
delay (100);
}