#include <Servo.h>
#include <LiquidCrystal_I2C.h>
int servoPin = 3;
int B1_PIN = 13;
int B2_PIN = 12;
int doorOpenPos = 0;
int doorClosePos = 90;
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo arm; // Create a "Servo" object called "arm"
void setup()
{
Serial.begin(115200);
pinMode(B1_PIN, INPUT_PULLUP);
pinMode(B2_PIN, INPUT_PULLUP);
arm.attach(servoPin); // Attache the arm to the pin 2
arm.write(doorClosePos); // Initialize the arm's position to 0 (leftmost)
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Auto Garage");
lcd.setCursor(0, 1);
lcd.print("Press Button");
}
void loop()
{
int b1Reading = digitalRead(B1_PIN);
int b2Reading = digitalRead(B2_PIN);
(b1Reading);
if (b1Reading == LOW) // Check for the yellow button input
{
arm.write(doorClosePos); // Set the arm's position to "pos" value
lcd.setCursor(0, 1);
lcd.print("Closing... ");
delay(2000);
lcd.setCursor(0, 1);
lcd.print("Closed ");
}
if (b2Reading == LOW) // Check for the blue button input
{
arm.write(doorOpenPos); // Set the arm's position to "pos" value
lcd.setCursor(0, 1);
lcd.print("Opening... ");
delay(2000);
lcd.setCursor(0, 1);
lcd.print("Opened ");
}
}