Rotates the servo motor to match the rotation on the potentiometer
Hardware used:
- Potentiometer
- Servo
Code Used:
- analogRead
- Library Import
- Servo Object
- Map function
#include <Servo.h>
/* Rotary encoder read example */
#define SERVO 5
#define POT 2
Servo myservo; // create servo object to control a servo
void setup()
{
myservo.attach(SERVO, 1000, 2000);
}
void loop()
{
myservo.write(map( analogRead(POT), 0, 1023, 0, 179));
// sets the servo position according to the scaled value
delay(10);
}