#include <LiquidCrystal_I2C.h>
#include <Servo.h>
const int ledRedPin = 5;
const int ledGreenPin = 4;
const int buttonLeftPin = 2;
const int buttonRightPin = 3;
const int servoPin = 6;
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo myServo;
int pos = 90;
void setup()
{
Serial.begin(115200);
Serial.println("Everything is okay.");
pinMode(ledRedPin, OUTPUT);
pinMode(ledGreenPin, OUTPUT);
pinMode(buttonLeftPin, INPUT);
pinMode(buttonRightPin, INPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Nothing is wrong");
myServo.attach(servoPin);
for(int i=0; i<10; i++)
{
digitalWrite(ledRedPin, HIGH);
digitalWrite(ledGreenPin,LOW);
delay(200);
digitalWrite(ledRedPin, LOW);
digitalWrite(ledGreenPin, HIGH);
delay(200);
}
digitalWrite(ledGreenPin, LOW);
}
void loop()
{
pos -= (digitalRead(buttonLeftPin) == LOW) ? 5 : 0;
pos += (digitalRead(buttonRightPin) == LOW) ? 5 : 0;
pos = constrain(pos, 0, 180);
myServo.write(pos);
delay(50);
}
Use the buttons for the Servo Motor.