safwan092

parking project 4 cars

Sep 5th, 2018
144
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3.  
  4. // Set the LCD address to 0x27 in PCF8574 by NXP and Set to 0x3F in PCF8574A by Ti
  5. LiquidCrystal_I2C lcd(0x3F, 20, 4);
  6.  
  7. byte customChar9[] = {
  8. 0x0E,
  9. 0x1F,
  10. 0x1F,
  11. 0x0E,
  12. 0x0E,
  13. 0x1F,
  14. 0x1F,
  15. 0x0E
  16. };
  17.  
  18.  
  19.  
  20.  
  21.  
  22. int ir1Pin = 3;
  23. int ir1 =0;
  24. int ir2Pin = 4;
  25. int ir2 =0;
  26. int ir3Pin = 5;
  27. int ir3 =0;
  28. int ir4Pin = 6;
  29. int ir4 =0;
  30.  
  31. void setup() {
  32. lcd.begin();
  33. lcd.createChar(9, customChar9);
  34. lcd.home();
  35. pinMode(ir1Pin, INPUT);
  36. pinMode(ir2Pin, INPUT);
  37. pinMode(ir3Pin, INPUT);
  38. pinMode(ir4Pin, INPUT);
  39. }
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. void loop() {
  47. ir1 = digitalRead(ir1Pin);
  48. ir2 = digitalRead(ir2Pin);
  49. ir3 = digitalRead(ir3Pin);
  50. ir4 = digitalRead(ir4Pin);
  51.  
  52. lcd.setCursor(0, 0);
  53. lcd.print(" Parking Spots:");
  54.  
  55. lcd.setCursor(2, 2);
  56. lcd.print("| 1 | 2 | 3 | 4 |");
  57.  
  58. //car 1
  59. if(ir1==1){
  60. lcd.setCursor(4, 2);
  61. lcd.write(9);
  62. }else{}
  63.  
  64. //car 2
  65. if(ir2==1){
  66. lcd.setCursor(8, 2);
  67. lcd.write(9);
  68. }else{}
  69.  
  70. //car 3
  71. if(ir3==1){
  72. lcd.setCursor(12, 2);
  73. lcd.write(9);
  74. }else{}
  75.  
  76. //car 4
  77. if(ir4==1){
  78. lcd.setCursor(16, 2);
  79. lcd.write(9);
  80. }else{}
  81.  
  82. delay(800);
  83. }
RAW Paste Data