Tanks, my goal is to have all servos listen to all pots. But i'd like to control the direction of servos independently for each pot also. here is the new code:
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott http://people.interaction-ivrea.it/m.rinott
#include <Servo.h>
Servo frontleft;
Servo rearleft;
Servo frontright;
Servo rearright;// create servo object to control a servo
int collectivestick = 0;
int elevatorstick = 1;
int aileronstick = 2;
int rudderstick = 3;// analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int val2;
int val3;
int val4;
int test;
int test2;
int test3;
int rudright;
void setup()
{
frontleft.attach(9); // attaches the servo on pin 9 to the servo object
frontright.attach(10);
rearleft.attach(11);
rearright.attach(12);
}
void loop()
{
val = analogRead(collectivestick); // reads the value of the potentiometer (value between 0 and 1023)
val2 = analogRead(aileronstick);
val3 = analogRead(elevatorstick);
val4 = analogRead(rudderstick);
test = analogRead(collectivestick);
test2 = analogRead(aileronstick);
test3 = analogRead(elevatorstick);
rudright = analogRead(rudderstick);
test = map(test, 0, 1023, 179, 0);
test2 = map(test2, 0, 1023, 179, 0);
test3 = map(test3, 0, 1023, 179, 0);
rudright = map(rudright, 0, 1023, 0, 89);
val2 = map(val2, 0, 1023, 0, 179);
val3 = map(val3, 0, 1023, 0, 179);
val4 = map(val4, 0, 1023, 89, 179);// scale it to use it with the servo (value between 0 and 180)
val = map(val, 0, 1023, 0, 179);
int mapval[]={
test,test2,test3,rudright,val2,val3,val4,val,
}; //array of variables for servo mapping
frontleft.write((val+val2+mapval[2])/3);
rearleft.write((mapval[1]+mapval[0]+mapval[2]+mapval[3])/4);
frontright.write((mapval[0]+val2+val3+mapval[3])/4);
rearright.write((mapval[1]+val+val3)/3); // sets the servo position according to the scaled value
delay(50); // waits for the servo to get there
}
I'm having trouble with the servos twitching and resting center positions at extremes. maybe my voltage is inconsistent.