#include <Servo.h>
#define POT_PIN 2
#define SRV_PIN 4
int potValue = 0;
int srvValue = 0;
Servo myservo;
void setup() {
pinMode(POT_PIN, INPUT);
pinMode(SRV_PIN, OUTPUT);
Serial.begin(115200);
myservo.attach(SRV_PIN);
myservo.write(0);
}
void loop() {
// range potValue = 0-4095 (12 bit)
// range servo = 0-180 (degree)
potValue = analogRead(POT_PIN);
srvValue = map(potValue, 0, 4095, 0, 180);
myservo.write(srvValue);
Serial.print("Sudut servo = ");
Serial.print(srvValue);
Serial.println(" derajat");
delay(100);
}