/*
 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 myservo,myservo1,myservo2,myservo3,myservo4;  // create servo object to control a servo

int potpin = 0, potpin1 = 1, potpin2 = 2, potpin3 = 3, potpin4 = 4, potpinall = 5;  // analog pin used to connect the potentiometer
int val, val1, val2, val3, val4, valall;    // variable to read the value from the analog pin

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo1.attach(8);
  myservo2.attach(7);
  myservo3.attach(6);
  myservo4.attach(5);
}

void loop() {
  // val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  // val = map(val, 0, 1023, 0, 180);     // 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

  // 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); 

  // val2 = analogRead(potpin2);            // reads the value of the potentiometer (value between 0 and 1023)
  // val2 = map(val2, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  // myservo2.write(val2); 

  // val3 = analogRead(potpin3);            // reads the value of the potentiometer (value between 0 and 1023)
  // val3 = map(val3, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  // myservo3.write(val3); 

  // val4 = analogRead(potpin4);            // reads the value of the potentiometer (value between 0 and 1023)
  // val4 = map(val4, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  // myservo4.write(val4);

  valall = analogRead(potpinall);            // reads the value of the potentiometer (value between 0 and 1023)
  valall = map(valall, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(valall); 
  valall = analogRead(potpinall);            // reads the value of the potentiometer (value between 0 and 1023)
  valall = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo1.write(valall); 
  valall = analogRead(potpinall);            // reads the value of the potentiometer (value between 0 and 1023)
  valall = map(valall, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo2.write(valall); 
  valall = analogRead(potpinall);            // reads the value of the potentiometer (value between 0 and 1023)
  valall = map(valall, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo3.write(valall); 
  valall = analogRead(potpinall);            // reads the value of the potentiometer (value between 0 and 1023)
  valall = map(valall, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo4.write(valall);  

}