HolyC0w

JCOMP_CSE2006

Apr 29th, 2022 (edited)
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //https://www.tinkercad.com/things/ivtC0MKTAIq?sharecode=kqTl0q02ZIBFl5zhS_UQjiV0t9DR3LVUrjSKAev2_fc
  2.  
  3. #include <LiquidCrystal.h>
  4. #include<Servo.h> //Library for the servo motor
  5.  
  6. Servo S1,S2; //Object of type servo
  7.  
  8. #define IR_Slot1 7 //Define pins
  9. #define IR_Slot2 8
  10. #define IR_entry 6
  11. #define IR_exit 13
  12.  
  13. int pos=0; //Initial Position of servo motor
  14. // initialize the library with the numbers of the interface pins
  15. LiquidCrystal lcd (12, 11, 5, 4, 3, 2);
  16.  
  17. void setup() {
  18.  
  19.   S1.attach(10); //Servo 1 on 10 pin
  20.   S2.attach(9);  //Servo 2 on 9 pin
  21.   S1.write(pos); //Inital position at 0 for both motors
  22.   S2.write(pos);
  23.  
  24.   pinMode(IR_Slot1, INPUT); //Pin modes
  25.   pinMode(IR_Slot2, INPUT);
  26.   pinMode(IR_entry, INPUT);
  27.   pinMode(IR_exit, INPUT);
  28.  
  29.  
  30.   lcd.begin(16, 2); //Initalize the 16x2 1cd
  31.   //Print a message to the LCD.
  32.   lcd.print(" Smart Parking");
  33.   lcd.setCursor(0, 1);  //Set cursor to column 1, row 2
  34.   lcd.print("    System");
  35.   delay(2000);
  36.   lcd.clear();  //Clear the led screen
  37.   lcd.setCursor(0, 0);  //Set cursor to column 1, row 0
  38.   lcd.print("Slot 1 = A");
  39.   lcd.setCursor(0, 1);  //Set cursor to column 1, row 1
  40.   lcd.print("Slot 2 = A");
  41.   delay(2000);
  42. }
  43.            
  44. void loop()
  45. {
  46.   if(digitalRead(IR_Slot1)==HIGH){
  47.     lcd.setCursor(0, 0);
  48.    
  49.     lcd.print("Slot 1 = NA");
  50.   }else{
  51.     lcd.setCursor(0, 0);
  52.  
  53.     lcd.print("Slot 1 = A");
  54.   }
  55.  
  56.   if(digitalRead(IR_Slot2)==HIGH){
  57.     lcd.setCursor(0, 1);
  58.    
  59.     lcd.print("Slot 2 = NA");
  60.   }else{
  61.     lcd.setCursor(0, 1);
  62.  
  63.     lcd.print("Slot 2 = A");
  64.   }
  65.  
  66. if(digitalRead(IR_entry)==HIGH && !(digitalRead(IR_Slot1)==HIGH && digitalRead(IR_Slot2)==HIGH)){
  67.     S1.write(pos+90);
  68.   }else{
  69.     S1.write(pos);
  70.   }
  71.  
  72.   if(digitalRead(IR_exit)==HIGH){
  73.     S2.write(pos+90);
  74.   }
  75.   else
  76.   {
  77.     S2.write(pos);
  78.   }
  79.  
  80.  
  81. }
  82.  
Add Comment
Please, Sign In to add comment