Servo library multiple servo support

I'm trying to run multiple servos using the Servo Library but the PWM isn't working when there's more than one servo.

#include <Arduino.h>
#include <Servo.h>

Servo _servos[] = {
        Servo(),
        Servo(),
        Servo(),
        Servo(),
};

void setup() {
    Serial.begin(9600);
    while (!Serial) { }
    for (byte i = 0; i < 4; i++) {
        const int pin = i + 2;
        const int angle = i * (180 / 3);
        Serial.println((i ? String(i) : "0") + ": Pin: " + String(pin) + ", Angle:  " + String(angle));
        _servos[i].attach(pin);
        _servos->writeMicroseconds(angle);
    }
}

void loop() {

}

Serial output

0: Pin: 2, Angle:  0
1: Pin: 3, Angle:  60
2: Pin: 4, Angle:  120
3: Pin: 5, Angle:  180

Waveforms 2, 3 & 4 all have a pulse width of ~1.5ms.

P.S. I've replicated it on both an Uno R3 and a Mega 2560.

I know next to nothing about the servo library, but that looks odd. Try:

Servo _servos[4];

That's wrong too.

_servos[i].write(angle);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.