#include <ESP32Servo.h>

int button_state = 0;
int lastState = LOW;
int currentState;
int angle = 0;
const int servo_pin = 19;

Servo servo; /* Servo = variabel dengan tipe servo, tipe variabel ini bisa dipakai kalau pakai library esp32servo.h*/

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  //Serial.println("Hello, ESP32!");
  /* pilih servo.attach yang atas atau yang bawah, keduanya sama aja
  bedanya yang bawah, bisa ngatur PWM nya*/
  servo.attach(servo_pin);
  //servo.attach(servo_pin, 500, 2400); /*servo.attach(pin, minimal pulse width in microseconds (at 0 degree) devaults value is 544, max pulse width in microseconds (max at 180 deg) defaults value is 2400) */
  servo.write(angle);
}

void loop() {
  // put your main code here, to run repeatedly:
  //delay(10); // this speeds up the simulation
  for (angle = 0; angle <= 180; angle +=1){
    servo.write(angle);
    delay(10);
  }
  for (angle = 180; angle >=0; angle -= 1){
    servo.write(angle);
    delay(10);
  }
  //if(button_state == HIGH) {
    //Serial.println("button on");
    //digitalWrite(led_pin, 1);
    //digitalWrite(buzzer_pin, 1);
    
    //}
}