Hello, I'm very new to arduino, servos, and writing code. All i would like to know, is how to control two servos separately with two different potentiometers. thanks!
You can do that by modifying the knob.pde servo example sketch.
Add another potPin for the second pot, . In loop duplicate the three lines before the delay statement so they refer to the second pot and second servo.
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2;
int potpin1 = 0; // analog pin used to connect the potentiometer
int potpin2 = 0;
int val; // variable to read the value from the analog pin
void setup()
{
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10); // attaches the servo on pin 10 to the servo object
}
void loop()
{
val = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo1.write(val); // sets the servo position according to the scaled value
val = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo2.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
gosh your smart... haha is there someplace on the web that teaches how to write code for the arduino from scratch? because i can't seem to find anything like that
im new as well and want to have 4 servos controlled by 4 diffrent pots please help with the code.
thank you
Untested:
#include <MegaServo.h>
#define N_SERVOS 4
#define FIRST_SERVO_PIN 2
#define FIRST_POT_PIN 0
Servo servo [N_SERVOS]; // create servo object to control a servo
void setup()
{
for (int i = 0; i < N_SERVOS; ++i) {
servo [i].attach(i + FIRST_SERVO_PIN);
}
}
void loop()
{
for (int i = 0; i < N_SERVOS; ++i) {
servo[i].write(map(analogRead(i + FIRST_POTPIN), 0, 1023, 0, 179) );
delay(15);
}
}
Simples!