#include <LiquidCrystal_I2C.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int boton1=2;
int boton2=3;
int boton3=4;
int boton4=5;
int servopin=A0;
int led1=10;
int led2=11;
int led3=12;
int led4=13;
Servo myservopin;
void setup() {
lcd.init();
lcd.backlight();
pinMode(boton1, INPUT);
pinMode(boton2, INPUT);
pinMode(boton3, INPUT);
pinMode(boton4, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop() {
myservopin.attach(servopin);
int b1=digitalRead(boton1);
int b2=digitalRead(boton2);
int b3=digitalRead(boton3);
int b4=digitalRead(boton4);
if (b1==HIGH) {
lcd.clear();
lcd.setCursor(4,1);
lcd.print("Izquierda");
digitalWrite(led1, HIGH);
delay(300);
myservopin.write(45);
}
else if(b2==HIGH){
lcd.clear();
lcd.setCursor(4,1);
lcd.print("Derecha");
digitalWrite(led2, HIGH);
delay(1500);
myservopin.write(135);
}
else if(b3==HIGH) {
lcd.clear();
lcd.setCursor(4,1);
lcd.print("arriba");
digitalWrite(led3, HIGH);
delay(300);
myservopin.write(90);
}
else if(b4==HIGH) {
lcd.clear();
lcd.setCursor(4,1);
lcd.print("abajo");
digitalWrite(led4, HIGH);
delay(1500);
myservopin.write(0);
}
else{
myservopin.write(0);
lcd.clear();
}
delay(50);
}