Just created a new ISR-based library enabling you to use 1 Hardware Timer
on an ESP8266-based board to control 16-or-more independent servo motors
. It’s quite simple to use.
Will soon expand to ESP32 and Arduino Mega, UNO, Nano, etc.
Here is the sample code
#define TIMER_INTERRUPT_DEBUG 1
#define ISR_SERVO_DEBUG 1
#include "ESP8266_ISR_Servo.h"
int servoIndex1 = -1;
int servoIndex2 = -1;
void setup()
{
Serial.begin(115200);
Serial.println("\nStarting");
servoIndex1 = ISR_Servo.setupServo(D8);
servoIndex2 = ISR_Servo.setupServo(D7);
if (servoIndex1 != -1)
Serial.println("Setup Servo1 OK");
else
Serial.println("Setup Servo1 failed");
if (servoIndex2 != -1)
Serial.println("Setup Servo2 OK");
else
Serial.println("Setup Servo2 failed");
}
void loop()
{
int position;
if ( ( servoIndex1 != -1) && ( servoIndex2 != -1) )
{
for (position = 0; position <= 180; position++)
{
// goes from 0 degrees to 180 degrees
// in steps of 1 degree
ISR_Servo.setPosition(servoIndex1, position);
ISR_Servo.setPosition(servoIndex2, 180 - position);
// waits 15ms for the servo to reach the position
delay(50 /*15*/);
}
for (position = 180; position >= 0; position--)
{
// goes from 180 degrees to 0 degrees
ISR_Servo.setPosition(servoIndex1, position);
ISR_Servo.setPosition(servoIndex2, 180 - position);
// waits 15ms for the servo to reach the position
delay(50 /*15*/);
}
}
}