RE: Software Servo Library

Hi Gang

Can someone clarify which of the following is the correct use of refresh() when using the Software Servo Library? Reading through the documentation it’s a little unclear.

Cheers

Jase :slight_smile:

Example 1
#include <SoftwareServo.h>

SoftwareServo servo;

void setup() {
  servo.attach(2);
  servo.setMinimumPulse(900);
  servo.setMaximumPulse(2100);
  for (int a = 0; a < 200; a++) {
    servo.write(90);
    SoftwareServo::refresh();
    delay(50);
  }
}

void loop() {

}

OR

Example 2
#include <SoftwareServo.h>

SoftwareServo servo;

void setup() {
  servo.attach(2);
  servo.setMinimumPulse(900);
  servo.setMaximumPulse(2100);
  servo.write(90);
  for (int a = 0; a < 200; a++) {
    SoftwareServo::refresh();
    delay(50);
  }
}

void loop() {

}

Neither is correct. refresh() is supposed to be called in loop().

Hi Paul

Thanks for getting back to me. I want the servo to centre once for 10 seconds at the start hence I've included a for loop in setup(). Are you saying this cannot/should not be done?

Cheers

Jase :)

I want the servo to centre once for 10 seconds at the start hence I've included a for loop in setup(). Are you saying this cannot/should not be done?

What do you think refresh() does? Why are you using SoftwareServo instead of Servo? What should the servo do after the 10 seconds is up?

The SoftwareServo::refresh() function needs to be called about once every 20 microseconds. The delay() calls have to go.

Hi Paul

I'll try and answer your questions one at a time.

  • I'm not entirely sure what refresh() does. Is it sufficient to simply call just refresh() regularly. Is servo.write() and SoftwareServo::refresh() a pigeon pair that need to be called regularly and sequentially?

  • I'm using the SoftwareServo library because I've a project in mind utilising the ATTiny. This does not support the standard servo library.

  • Once the 10 seconds are up then I hope to use the servo to pan a camera.

  • I'm assuming your strong recommendation not to use 'delay()' is because it's really aimed at beginners? I've been checking out the 'Blink Without Delay' sketch.

Cheers

Jase :)

Is it sufficient to simply call just refresh() regularly.

Yes, as long as you understand that regularly doesn't happen with delay() in the code.

I'm assuming your strong recommendation not to use 'delay()' is because it's really aimed at beginners?

No, it's because it is blocking code. While the delay() function is wasting time, the Arduino can't be doing other things, like refreshing the servo data.

Hi Paul

Sorry for the late reply (9mth old son). Thanks for your help.

Cheers

Jase :)

He meant every 20 milliseconds, BTW