#include <Servo.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x027, 16, 2);
Servo servo;
int angle =0;
int direction=1;
int pot = A0;
int speed=0;
void setup() {
// put your setup code here, to run once:
servo.attach(11);
lcd.begin(16,2);
lcd.backlight();
lcd.setCursor(0,0);
}
void loop() {
// put your main code here, to run repeatedly:
speed = map(analogRead(pot),0,1023, 50,10);
if(angle>180)
{
angle=180;
direction=-1;
}
if(angle < 0)
{
angle =0;
direction=1;
}
angle += direction;
servo.write(angle);
lcd.print("angle: ");
lcd.print(angle);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("speed: ");
lcd.print(speed);
lcd.print(" ");
lcd.setCursor(0,0);
delay(speed);
}