#include "ESP32_Servo.h"

// Youtube
// https://www.youtube.com/watch?v=cDbd0ASkMog

Servo myservo;  // create servo object to control a servo
// 16 servo objects can be created on the ESP32

int pos = 0;    // variable to store the servo position
// Recommended PWM GPIO pins on the ESP32 include 2,4,12-19,21-23,25-27,32-33
int servoPin = 18;
int tp = 4;

//  When you call servo.attach(pin); the servo will, by default, move to 90.
//  If you want it to go elsewhere, use servo.write(angle); BEFORE servo.attach(pin).
void setup() {
  pinMode(tp, OUTPUT);
  digitalWrite(tp, HIGH);
  myservo.attach(servoPin, 500, 2400);   // attaches the servo on pin 18 to the servo object
  digitalWrite(tp, LOW);
  myservo.write(10);
  delay(500);
  while (1);




  // using default min/max of 1000us and 2000us
  // different servos may require different min/max settings
  // for an accurate 0 to 180 sweep
}

void loop() {
  digitalWrite(tp, HIGH);
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(10);                       // waits 15ms for the servo to reach the position
  }
  digitalWrite(tp, LOW);
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(10);                       // waits 15ms for the servo to reach the position
  }
}
D0D1D2D3D4D5D6D7GNDLOGIC