Skip to content

Instantly share code, notes, and snippets.

@sixhat
Created November 23, 2026 14:40
Show Gist options
  • Select an option

  • Save sixhat/dbfdff84fc28abea58bd4c6ebef2b4bf to your computer and use it in GitHub Desktop.

Select an option

Save sixhat/dbfdff84fc28abea58bd4c6ebef2b4bf to your computer and use it in GitHub Desktop.
Controling two sg90 servos with ESP32 boards
/*
Exemplo de correr dois servos ao mesmo tempo numa ESP32
*/
#include <ESP32Servo.h>
Servo s2;
Servo s3;
int it;
void setup()
{
Serial.begin(9600);
ESP32PWM::allocateTimer(0);
ESP32PWM::allocateTimer(1);
ESP32PWM::allocateTimer(2);
ESP32PWM::allocateTimer(3);
s2.setPeriodHertz(50);
s3.setPeriodHertz(50);
s2.attach(D2, 500, 2400);
s3.attach(D3, 500, 2400);
it = 0;
}
void loop()
{
s2.write(90);
s3.write(90);
delay(1000);
s2.write(10);
s3.write(10);
delay(1000);
s2.write(90);
s3.write(90);
delay(1000);
s2.write(170);
s3.write(170);
delay(1000);
Serial.println(it++);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment