Created
June 11, 2020 08:42
-
-
Save dsijanov/93f4cbcc7eb4c368df71e98ac9f32312 to your computer and use it in GitHub Desktop.
Smart parking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> //It adds the library to the program. | |
#include <LiquidCrystal.h> | |
Servo rampa; //It creates a servo object that manages the servo. | |
int izlaz = 0; //Pin attached to the sensor at the exit. | |
int ulaz = 1; //Pin attached to the sensor at the entrance. | |
int spusteno = 177; //Position of the ramp down. | |
int dignuto = 90; //Position of the ramp up. | |
int kapacitet = 6; //The capacity of the parking. | |
int slobodnaMjesta = 6; //The number of vacancies (the parking lot is initially empty). | |
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2; //It initializes the library by adding required pins for LCD | |
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); //to the pin to which Arduino is connected. | |
byte znak[8] = { //It creates the data for a character that is printed on | |
B11011, //LCD, but it is not a standard alphanumeric (Z) | |
B01110, //necessary to print the message “Unfortunately, there are no vacancies”. | |
B00000, | |
B11111, | |
B00110, | |
B01100, | |
B11111, | |
}; | |
void setup() { | |
rampa.attach(9); //It connects the servo. | |
pinMode(izlaz, INPUT); //It sets the pins' of the sensors for entrance and exit as input. | |
pinMode(ulaz, INPUT); | |
rampa.write(spusteno); //It sets the ramp to the down position. | |
lcd.begin(16, 2); //It sets the number of characters and rows on the LCD. | |
lcd.setCursor(2, 0); | |
lcd.print("Super Mega"); //It prints the message on the LCD. | |
lcd.setCursor(4, 1); | |
lcd.print("PARKING"); | |
delay(2000); | |
lcd.clear(); | |
lcd.createChar(0, znak); | |
lcd.begin(16, 2); | |
} | |
void loop() { | |
if (digitalRead(ulaz) == 0) | |
{ | |
if (slobodnaMjesta != 0) { | |
delay(500); | |
slobodnaMjesta--; | |
rampa.write(dignuto); | |
lcd.print("Slobodna mjesta:"); | |
lcd.setCursor(5, 1); | |
lcd.print(slobodnaMjesta); | |
delay(3000); | |
rampa.write(spusteno); | |
} else { | |
delay(500); | |
lcd.print("Na"); | |
lcd.write(byte(0)); | |
lcd.print("alost, nema"); | |
lcd.setCursor(0, 1); | |
lcd.print("slobodnih mjesta"); | |
delay(2000); | |
} | |
} | |
if (digitalRead(izlaz) == 0) | |
{ | |
if (slobodnaMjesta != kapacitet) { | |
delay(500); | |
slobodnaMjesta++; | |
rampa.write(dignuto); | |
lcd.print("Slobodna mjesta:"); | |
lcd.setCursor(5, 1); | |
lcd.print(slobodnaMjesta); | |
delay(3000); | |
rampa.write(spusteno); | |
} | |
} | |
lcd.clear(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment