Click here and download App
CODE
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int pos = 0;
int x=0;
int y=0;
Servo myservo1, myservo2;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
myservo1.attach(10); // attach servo signal wire to pin 9
myservo2.attach(9);
myservo1.write(0);
myservo1.write(0);
Serial.begin(9600);
lcd.begin(16, 2);
lcd.backlight();
updateLCD(); //
}
void loop()
{
if(Serial.available()>0)
{
pn=Serial.read();
Serial.print(pn);
}
if (pn == 'A')
{
for (pos = x; pos <= 180; pos += 1) {
myservo1.write(pos);
delay(10);
x =x+1;
updateLCD();
break;
pn = 0;
}}
if (pn == 'B')
{
for (pos = x; pos >= 0; pos -= 1) {
myservo1.write(pos);
delay(10);
x =x-1;
updateLCD();
break;
pn = 0;
}}
if (pn == 'C')
{
for (pos = y; pos <= 180; pos += 1) {
myservo2.write(pos);
delay(10);
y =y+1;
updateLCD();
break;
pn = 0;
}}
if (pn == 'D')
{
for (pos = y; pos >= 0; pos -= 1) {
myservo2.write(pos);
delay(10);
y =y-1;
updateLCD();
break;
pn = 0;
}
}
}
void updateLCD() {
lcd.setCursor(0, 0);
lcd.print("Servo1: ");
lcd.print(x);
lcd.print(" "); //
lcd.setCursor(0, 1);
lcd.print("Servo2: ");
lcd.print(y);
lcd.print(" ");
}