// ------------------------------------------
/*
* Hardware{
* servo : GPIO12
* potentiometer : GPIO13
* }
*/
// ------------------------------------------
#include <Arduino.h>
#include <ESP32Servo.h>
// ------------------------------------------
#define SERVO_PIN (12)
Servo SERVO;
#define POTENTIOMETER (34)
#define TICKRATE (20)
void setup() {
Serial.begin(115200);
SERVO.setPeriodHertz(50);
SERVO.attach(SERVO_PIN, 500, 2400);
Serial.println("Servo implemented");
}
void loop() {
int potValue = analogRead(POTENTIOMETER);
int angle = map(potValue, 0, 4095, 0, 180);
SERVO.write(angle);
Serial.print("Potentiometer: ");
Serial.print(potValue);
Serial.print("\tAngle: ");
Serial.println(angle);
delay(TICKRATE);
}