NEWBIE Servo control!!

Newbie Alert!!

I have two servos, which I can control via sweep using my nano.

What I would like to do though is....

Have Servo No1 sweep
Sweep 2 or 3 times and then PAUSE

Then have

Servo No2 sweep, PAUSE

and for the routine to loop.

Is this possible?

I've been searching everywhere but obviously not in the right places!!

Any help would be gratefully received.

Thanks,

Jon

You got sweep to work and you want new, different behavior. Have you tried writing code for that? Did you get sweep to work for both servos?

Post code. Use code tags </>

We can help you from there.

Hi,
If you can get sweep to work once, then just repeat in both directions, wait then do the same with servo 2, it really is so simple! We all have to start somewhere so give it a try. Yes you will make mistakes, but it's the only way to learn..... If this is what you want to do.

Lets see your code and circuit, etc if you want more help.

Regards

Mel.

Thanks so much for your help.
Here is the code I've been playing with. I know very simple, but I still cant get it to work!!
Servo2 isnt working and I want a delay between servo1 and servo2 but everytime I play with the delay the servo gets slower. Is there a different command I should be using?
Thanks again in advance.

<#include <Servo.h>

Servo servo1;// moves eyes
Servo servo2;// moves eyelids

int pos1;      // angle of servo1
int pos2;      // angle of servo2

void setup()
{
servo1.attach(9);  // attaches the servo on pin 9 to the servo object
servo2.attach(10);  // attaches the servo on pin 10 to the servo object
} 


void loop() {
 for (pos1 = 0; pos1 <= 180; pos1 += 1) { // goes from 0 degrees to 180 degrees
   // in steps of 1 degree
   servo1.write(pos1);              // tell servo to go to position in variable 'pos1'
   delay(10);                       // waits 10ms for the servo to reach the position
 }
 for (pos1 = 180; pos1 >= 0; pos1 -= 1) { // goes from 180 degrees to 0 degrees
   servo1.write(pos1);              // tell servo to go to position in variable 'pos1'
   delay(10);                       // waits 10ms for the servo to reach the position

void loop() {
 for (pos2 = 0; pos2 <= 180; pos2 += 1) { // goes from 0 degrees to 180 degrees
   // in steps of 1 degree
   servo2.write(pos2);              // tell servo to go to position in variable 'pos2'
   delay(10);                       // waits 10ms for the servo to reach the position
 }
 for (pos2 = 180; pos2 >= 0; pos2 -= 1) { // goes from 180 degrees to 0 degrees
   servo1.write(pos2);              // tell servo to go to position in variable 'pos2'
   delay(10);                       // waits 10ms for the servo to reach the position
 }
}

It looks like you missed using the code tags. You can go back to your post, hit Modify, highlight the source and click the code tag button in the upper left that looks like this </>

It looks like you have the void loop() defined twice. Don't do that. Delete the second definition.

Thanks,

I was using Firefox and it didnt give me the option!
Working with Chrome now and all the features are there.

I've removed the second void loop buut now it states I have:
/tmp/780431598/2_servos/2_servos.ino:36:1: error: expected '}' at end of input
exit status 1

Thanks again,

Jon

<#include <Servo.h>

Servo servo1;// moves eyes
Servo servo2;// moves eyelids

int pos1;      // angle of servo1
int pos2;      // angle of servo2

void setup()
{
servo1.attach(9);  // attaches the servo on pin 9 to the servo object
servo2.attach(10);  // attaches the servo on pin 10 to the servo object
} 


void loop() {
 for (pos1 = 0; pos1 <= 180; pos1 += 1) { // goes from 0 degrees to 180 degrees
   // in steps of 1 degree
   servo1.write(pos1);              // tell servo to go to position in variable 'pos1'
   delay(10);                       // waits 10ms for the servo to reach the position
 }
 for (pos1 = 180; pos1 >= 0; pos1 -= 1) { // goes from 180 degrees to 0 degrees
   servo1.write(pos1);              // tell servo to go to position in variable 'pos1'
   delay(10);                       // waits 10ms for the servo to reach the position

void loop() {
 for (pos2 = 0; pos2 <= 180; pos2 += 1) { // goes from 0 degrees to 180 degrees
   // in steps of 1 degree
   servo2.write(pos2);              // tell servo to go to position in variable 'pos2'
   delay(10);                       // waits 10ms for the servo to reach the position
 }
 for (pos2 = 180; pos2 >= 0; pos2 -= 1) { // goes from 180 degrees to 0 degrees
   servo1.write(pos2);              // tell servo to go to position in variable 'pos2'
   delay(10);                       // waits 10ms for the servo to reach the position
 }
}

No you still have two void loop() entries, line 16 and line 26. And your include on line 1 doesn't compile because it's got a spare < character in front of it. I can't see any attempt to get servo1 to sweep several times and there is nothing that puts a pause between servo1 sweeping and servo2 starting or a pause after servo2 finishes.

If you fix the include, replace line 26 with something like delay(5000); and sort the } braces out then at least you might get servo1 sweeping, 5 second delay then servo2 sweeping.

Steve