#include <ESP32Servo.h>

const unsigned long SERVO_INTERVAL = 100;
const int SERVO_PIN = 18;

unsigned long prevServoTime = 0;
int pos = 0;
int increment = 1;

Servo servo;

void setup() {
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");
  servo.attach(SERVO_PIN);
}

void loop() {
  delay(10); // this speeds up the simulation
  
  if (millis() - prevServoTime >= SERVO_INTERVAL) {
    prevServoTime = millis();
    pos = pos + increment;
    if (pos >= 180) increment = -1;
    if (pos <= 0) increment = 1;
    servo.write(pos);
  }
}