void servoWrite(int pin, int angle)
{
int duty = map(angle, 0, 180, 400, 2000);
ledcWrite(pin, duty);
}
void setup()
{
for (int channel = 0; channel < 4; ++channel)
{
ledcSetup(channel, 50, 14);
ledcAttachPin(channel + 4, channel);
}
for (int angle = 90; angle > 0; --angle)
{
for (int channel = 0; channel < 4; ++channel)
{
servoWrite(channel, angle);
delay(5);
}
}
}
void loop()
{
for (int angle = 0; angle < 180; ++angle)
{
for (int channel = 0; channel < 4; ++channel)
{
servoWrite(channel, angle);
delay(5);
}
}
for (int angle = 180; angle > 0; --angle)
{
for (int channel = 0; channel < 4; ++channel)
{
servoWrite(channel, angle);
delay(5);
}
}
}