I am trying to design a control system for a robot. I have 4 servos linked to 4 pots. my goal is to write the the position data of all pots to all servos simultaneously. i want each pot to make the set of 4 servos attached to it behave slightly differently than the next pot. i am not familiar enough with the language to put the code together. i have attached a pic of the project and the code. Any advise will be appreciated. thanks
// Controlling a set of servos positioning using multiple potentiometers (variable resistor)
// by Brian McDonald modified from knob sketch.
#include <Servo.h>
Servo frontleft; // create servo object to control a servo
Servo frontright;
Servo backright;
Servo backleft;
int collective = 0;// analog pin used to connect the potentiometer
int elevator = 1;
int alieron = 2;
int rudder = 3;
int collectivevar; // variable to read the value from the analog pin pot
int elevatorvar;
int alieronvar;
int ruddervar;
void setup()
{
frontleft.attach(9); // attaches the servo on pin to the servo object
frontright.attach(10);
backleft.attach(11);
backright.attach(12);
Serial.begin(9600);
}
void loop()
{
collectivevar = analogRead(collective); // reads the value of the potentiometer (value between 0 and 1023)
elevatorvar = analogRead(elevator);
alieronvar = analogRead(alieron);
ruddervar = analogRead(rudder);
collectivevar = map(collectivevar, 0 ,1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
elevatorvar = map(elevatorvar, 0, 1023, 0, 179);
alieronvar = map(alieronvar, 0, 1023, 0, 179);
ruddervar = map(ruddervar, 0 , 1023, 0, 179);
frontleft.write(elevatorvar+collectivevar+alieronvar+ruddervar); // sets the servo position according to the scaled value
frontright.write(elevatorvar+collectivevar+alieronvar+ruddervar);
backleft.write(elevatorvar+collectivevar+alieronvar+ruddervar);
backright.write(elevatorvar+collectivevar+alieronvar+ruddervar);
Serial.println(collectivevar); // Gives pot reading 0-179
delay(1); // waits for the servo to get there
}