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.