/*
This project is originally made by Uri Shaked
This is edited by terckjix
*/
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
Servo myservo; // create servo object to control a servo
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16 chars and 2 line display
int potpin = 0; // analog pin used to connect the potentiometer
int potValue; // variable to read the value from the analog pin
int servoAngle; // variable to store the angle of the servo
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
lcd.init(); // initialize the lcd
lcd.backlight(); // turn on the backlight
}
void loop() {
potValue = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
servoAngle = map(potValue, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(servoAngle); // sets the servo position according to the scaled value
// Display the servo angle on the LCD
lcd.clear();
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print("Servo Angle:");
lcd.setCursor(0, 1); // set the cursor to column 0, line 1
lcd.print(servoAngle);
delay(15); // waits for the servo to get there
}