I found someones code and circuit for controlling a servo with one pot and tried to figure out how to duplicate it on my own. I have already heard that potentiometers are not the best way of controlling servos so if you have another way feel free to tell me but I still need help with the supplies that I have. I know how to set up the physical circuit so I just need help to make sure the code is written correctly. I would just try it but the last time I just tried code my board died and I'm not rich.
// Controlling 13 servos position using potentiometers
#include <Servo.h>
Servo servo0; // create servo object to control a servo
Servo servo1; // create servo object to control a servo
Servo servo2; // create servo object to control a servo
Servo servo3; // create servo object to control a servo
Servo servo4; // create servo object to control a servo
Servo servo5; // create servo object to control a servo
Servo servo6; // create servo object to control a servo
Servo servo7; // create servo object to control a servo
Servo servo8; // create servo object to control a servo
Servo servo9; // create servo object to control a servo
Servo servo10; // create servo object to control a servo
Servo servo11; // create servo object to control a servo
Servo servo12; // create servo object to control a servo
int val0; // variable to read the value from the analog pin
int val1; // variable to read the value from the analog pin
int val2; // variable to read the value from the analog pin
int val3; // variable to read the value from the analog pin
int val4; // variable to read the value from the analog pin
int val5; // variable to read the value from the analog pin
int val6; // variable to read the value from the analog pin
int val7; // variable to read the value from the analog pin
int val8; // variable to read the value from the analog pin
int val9; // variable to read the value from the analog pin
int val10; // variable to read the value from the analog pin
int val11; // variable to read the value from the analog pin
int val12; // variable to read the value from the analog pin
int potpin0 = 0; // analog pin used to connect the potentiometer
int potpin1 = 1; // analog pin used to connect the potentiometer
int potpin2 = 2; // analog pin used to connect the potentiometer
int potpin3 = 3; // analog pin used to connect the potentiometer
int potpin4 = 4; // analog pin used to connect the potentiometer
int potpin5 = 5; // analog pin used to connect the potentiometer
int potpin6 = 6; // analog pin used to connect the potentiometer
int potpin7 = 7; // analog pin used to connect the potentiometer
int potpin8 = 8; // analog pin used to connect the potentiometer
int potpin9 = 9; // analog pin used to connect the potentiometer
int potpin10 = 10; // analog pin used to connect the potentiometer
int potpin11 = 11; // analog pin used to connect the potentiometer
int potpin12 = 12; // analog pin used to connect the potentiometer
void setup()
{
servo0.attach(0); // attaches the servo on pin 0 to the servo object
servo1.attach(1); // attaches the servo on pin 1 to the servo object
servo2.attach(2); // attaches the servo on pin 2 to the servo object
servo3.attach(3); // attaches the servo on pin 3 to the servo object
servo4.attach(4); // attaches the servo on pin 4 to the servo object
servo5.attach(5); // attaches the servo on pin 5 to the servo object
servo6.attach(6); // attaches the servo on pin 6 to the servo object
servo7.attach(7); // attaches the servo on pin 7 to the servo object
servo8.attach(8); // attaches the servo on pin 8 to the servo object
servo9.attach(9); // attaches the servo on pin 9 to the servo object
servo10.attach(10); // attaches the servo on pin 10 to the servo object
servo11.attach(11); // attaches the servo on pin 10 to the servo object
servo12.attach(12); // attaches the servo on pin 10 to the servo object
}
void loop()
{
val0 = analogRead(potpin0); // reads the value of the potentiometer (value between 0 and 1023)
val1 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val2 = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
val3 = analogRead(potpin3); // reads the value of the potentiometer (value between 0 and 1023)
val4 = analogRead(potpin4); // reads the value of the potentiometer (value between 0 and 1023)
val5 = analogRead(potpin5); // reads the value of the potentiometer (value between 0 and 1023)
val6 = analogRead(potpin6); // reads the value of the potentiometer (value between 0 and 1023)
val7 = analogRead(potpin7); // reads the value of the potentiometer (value between 0 and 1023)
val8 = analogRead(potpin8); // reads the value of the potentiometer (value between 0 and 1023)
val9 = analogRead(potpin9); // reads the value of the potentiometer (value between 0 and 1023)
val10 = analogRead(potpin10); // reads the value of the potentiometer (value between 0 and 1023)
val11 = analogRead(potpin11); // reads the value of the potentiometer (value between 0 and 1023)
val12 = analogRead(potpin12); // reads the value of the potentiometer (value between 0 and 1023)
val0 = map(val0, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
val1 = map(val1, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
val2 = map(val2, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
val3 = map(val3, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
val4 = map(val4, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
val5 = map(val5, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
val6 = map(val6, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
val7 = map(val7, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
val8 = map(val8, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
val9 = map(val9, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
val10 = map(val10, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
val11 = map(val11, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
val12 = map(val12, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
servo0.write(val0); // sets the 0 servo position according to the scaled value
servo1.write(val1); // sets the 1 servo position according to the scaled value
servo2.write(val2); // sets the 2 servo position according to the scaled value
servo3.write(val3); // sets the 3 servo position according to the scaled value
servo4.write(val4); // sets the 4 servo position according to the scaled value
servo5.write(val5); // sets the 5 servo position according to the scaled value
servo6.write(val6); // sets the 6 servo position according to the scaled value
servo7.write(val7); // sets the 7 servo position according to the scaled value
servo8.write(val8); // sets the 8 servo position according to the scaled value
servo9.write(val9); // sets the 9 servo position according to the scaled value
servo10.write(val10); // sets the 10 servo position according to the scaled value
servo11.write(val11); // sets the 11 servo position according to the scaled value
servo12.write(val12); // sets the 10 servo position according to the scaled value
delay(15); // waits for the servos to get there
}