Hi guys
I'm working with some servoes at the moment and I need some of your awesome advises.
I want to control 2-3 Servos at the same time with 2-3 potentiometers. I can make it work when I use Processing or MAX/ msp with my arduino. but i also need it to work only with the Arduino.
To begin I just want each servo to sweep between 0-180 degrees. The speed of each servo should be controlled by one of the 2-3 potentiometers. so servo1 is controlled by pot1 and servo2 is controlled by pot2
I got this working but the problem for me is that they take one servo at a time and i need it to be done at the same time.
So my question is how I combine this code so they all can be controlled at the same time.
hope you can help.
All the best
-Ken
//Build on the Servo Example Sweep
// by BARRAGAN http://barraganstudio.com
// This example code is in the public domain.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo myservo1; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int potpin1 = 1; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int val1; // variable to read the value from the analog pin
int pos = 0; // variable to store the servo position
int pos1 = 0;
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo1.attach(10); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
val=analogRead(potpin);
val=map(val,0,1023,20,1);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(val); // waits (val)ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
val=analogRead(potpin);
val=map(val,0,1023,20,1);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(val); // waits (val)ms for the servo to reach the position
}
for(pos1 = 0; pos1 < 180; pos1 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
val1=analogRead(potpin1);
val1=map(val1,0,1023,20,1);
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(val1); // waits (val)ms for the servo to reach the position
}
for(pos1 = 180; pos1>= 1; pos1 -=1) // goes from 180 degrees to 0 degrees
{
val1=analogRead(potpin1);
val1=map(val1,0,1023,20,1);
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(val1); // waits (val)ms for the servo to reach the position
}
}