/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
Servo myservo; // create servo object to control a servo
float potpin = 0; // analog pin used to connect the potentiometer
float vbat; // variable to read the value from the analog pin
int val=0;
int tmg=0;
void setup() {
lcd.init();
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
delay(200);
vbat = analogRead(potpin);
vbat = map(vbat,0,1023,1500,3000);
vbat = vbat/100;
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("VBAT ");
lcd.print(vbat);
if(vbat<22 ){
val=180;
while(val>10){
val=val-1;
delay(10);
myservo.write(val);
}
}
}