Erratic behavior from servo?

I am trying to get a servo to move to 2 positions. Simple enough. I made a function, specify the angle, servo is to move there.
Simple enough right?

Well, not quite. Have a look at this video and see what is happening:

The code:

    Servo myServoName;
    int pos = 0;

    void setup() {
        myServoName.attach( A5 );
        Spark.function("setpos", setPosition);
        Spark.variable("getpos", &pos, INT);

    void loop() {

    int setPosition(String posValue) {
        pos = posValue.toInt();
        return 0;

The other servo works just fine.

Any ideas?

What type servo is that?
And what is “the other servo”?
Have you tried myServoName.writeMicroseconds() instead?

BTW, you are still using the deprecated Spark object and also the deprecated three three parameter version for Particle.variable()
Just for the sake of it, I’d also return pos; instead of 0 to get some useful feedback for the function call.

1 Like

Oh shucks, copied some old code over, hence the deprecated objects.
Let me see what writeMicroseconds does and if it helps.

Yup, that did it!

1 Like