this example used only 2 servos. Is it possible to use 3-4 servos without overwriting a ton of stuff?
i'd really rather not spend 35$ to find out it's limited
#include <Servo.h>
Servo servo1; Servo servo2;
void setup() {
pinMode(2,OUTPUT);
servo1.attach(14); //analog pin 0
//servo2.attach(15); //analog pin 1
Serial.begin(19200);
}
void loop() {
static int v = 0;//
v = v +=1;
if (v == 180){
v = 0;
servo1.write(v);
//Servo::refresh();
Serial.println(v);
}
Serial.println(v);
delay(100);
servo1.write(v);//
Servo::refresh();//
}
no... im just goign to try and edit the code to do 3... if it no work i'll cry. gps shield dun come with like ANY extra plugs and radio shaft doesnt sell em
ordered all the male/female header pins i could ever need lol and a wireless virtual wire for arduino. I totally forgot i took apart my botanical plant growing boarduino so i'll use that to test the servo thing
okies so from what i've seen... take the example above and add more servos and keep using analog pins... just add on to the
servo servo#;
declare servo pin as the analog pin
and servo.write
i'm just using 1 servo and connecting it onto servo 1, 2, & 3
errors:
i have no clue i think my boarduino is damaged.. cause it will run the program for a while then stop. it's doing some other buggy things in the monitor tho too...
In the code you posted, "delay(100)" is going to cause you problems. You need to keep refreshing the servos every 40ms or so.
Secondly, what's this "v = v +=1" ? wouldn't it be better to write: "v +=1" or "v++" ?
Using multiple servos should be no problem. (I've used 2 before, and 3 should be no big deal afaik.)
unsigned long cur_tm = millis();
unsigned long pre_tm = cur_tm;
int delay = 100;
void setup()
{
...
}
void loop()
{
static int v = 0;
cur_tm = millis();
// determine how many ms have passed
// if your code runs for more than 9 hours, need to handle
// millis() overflow
if( cur_tm - pre_tm > delay )
{
v++;
if( v > 180 )
v = 0;
servo1.write(v);
servo2.write(v);
servo3.write(v);
Serial.print("Moved servos to position: ");
Serial.println(v, DEC);
// record previous measured time
// (difference is set to zero since we met our delay time)
pre_tm = cur_tm;
}
// refresh often
Servo::refresh();
}