byte servo1 = 13;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(servo1, OUTPUT);
}
void loop() {
posicion( 180);
delay(5000); // this speeds up the simulation
posicion(0);
delay(5000);
}
void posicion(int G)
{
int res =0;
int Angulo = map(G,0,180,540,2400);
for(byte i=0;i<42;i++)
{
res=20,000-Angulo;
digitalWrite(servo1, HIGH);
delayMicroseconds(Angulo);
digitalWrite(servo1, LOW);
delayMicroseconds(res);
}
}