Moving two servos incrementally every second

Hi, I am controlling the position of two servo's, (say A and B)

Let's say servo A and B both start at 1000ms position:

ServoA.writeMicroseconds(1000);
ServoB.writeMicroseconds(1000);

I want to be able to add to the position incrementally every second so say servo A starts at 1000 and moves 100ms every second and servo B starts at 1000 and moves 10ms every second.

I know I have to define two values, add to them every pass, then send that value to the servo position but I am slightly unsure on how to code this.

I think it is something like this:

Int APulse;
Int BPulse;

Void setup() {

APulse = 1000;
BPulse = 1000;

Void loop() {

ServoA.writeMicroseconds(APulse);
ServoB.writeMicroseconds(BPulse);

(this is the bit I don't understand, adding to APulse, BPulse by 100ms and 10ms, then feeding it back in
To the next loop)

Delay 1000; delays by a second then back around again.

}

From looking into example code I am assuming I need to use the map command but don't quite understand it.

Thanks!

Break it down into several, smaller problems -- you need to:

  1. Measure the passing of time (so you can do something once every second)
  2. Change a value
  3. Write the changed value

So, consider the following pseudo-code and go from there..

if currentTime - lastTime greater than threshold
   then 
       increment value
       write to motor
       set lastTime to now

To change the value in a variable, just set its new value - you can even use its old value to set it, e.g.:

  var1 = var1 + 10;

The scope of the variable determines its life... If you declare it global (outside of a function), any changes you make are global, you can access it again from anywhere else, e.g.:

int foo = 1;

void setup() {
}

void loop() {

  foo = foo + 1;
}

!c

flotilla:

Void loop() {

ServoA.writeMicroseconds(APulse);
   ServoB.writeMicroseconds(BPulse);

/* (this is the bit I don't understand, adding to APulse, BPulse by 100ms and 10ms, then feeding it back in
To the next loop) */

delay(1000);
}

You can use:

    APulse = APulse + 100;
    BPulse = BPulse + 10;

Or the shorthand version:

    APulse += 100;
    BPulse += 10;

You may want to add code for what to do when you reach 2000.

Thankyou both very much. Very helpful and a lot simpler than I thought.

All the best

F