#include <Servo.h>
#include <LiquidCrystal_I2C.h>
int servoPin = 3; ///this is for the servo
int B1_PIN = 13; ///this sis for the buttons
int B2_PIN = 12;
int doorOpenPos = 0; ///this is where servo will be when door is closed
int doorClosePos = 90; ///this is where the servo will be when door is open
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo 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"); ///this is the first text that will appear
lcd.setCursor(0, 1);
lcd.print("Press Button");
}
void loop() //this is a loop
{
int b1Reading = digitalRead(B1_PIN); //this is for button 1
int b2Reading = digitalRead(B2_PIN); ///this is for button 2
(b1Reading);
////if you press button 1 this happens
if (b1Reading == LOW) // Check for the yellow button input
{
arm.write(doorClosePos); // Set the arm's position to "pos" value
lcd.setCursor(0, 1); ////this is where its gonna be placed on the board
lcd.print("Closing... ");
delay(2000); //this is how long you have to wait for the next text to appear
lcd.setCursor(0, 1); ////this is where its gonna be placed on the board
lcd.print("Closed ");
}
////if you press button 2 this happens
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... "); ///this is the text that appears
delay(2000); ///you have to wait 2 seconds for the new text to appear
lcd.setCursor(0, 1); ////this is where its gonna be placed on the board
lcd.print("Opened "); //this is the last text
}
}