Was wondering if anyone could help with this arduino project i’m doing, it involves 2 servos connected to an external power supply, and each having their own digital pin. They share one potentiometer. I have the two servos facing opitsite to each other, therefore i need to flip one’s direction but cant seem to work it out You’ll probably see what i’m trying to get at if you have a look at my code
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
Servo myservo2;
int potpin2 = 0;
int val2;
void setup()
{
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10);
}
void loop()
{
val = analogRead(potpin); // 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)
val2 = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
val2 = map(val, 0, 1023, 179, 1); // 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
myservo2.write(val2);
delay(15); // waits for the servo to get there
}
Im fairly new to arduino as you can probably tell, but have read about servos and basic functions etc. Thanks in advance