safwan092

Project 961 - arduino mega code - rev 01

Jun 14th, 2020
132
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. //LCD Lib
  3. int p1Red = 22;
  4. int p2Red = 24;
  5. int p3Red = 26;
  6.  
  7. int p1Green = 23;
  8. int p2Green = 25;
  9. int p3Green = 27;
  10.  
  11. int p1Pin = 14;
  12. int p2Pin = 15;
  13. int p3Pin = 16;
  14.  
  15. int p1Status = 0;
  16. int p2Status = 0;
  17. int p3Status = 0;
  18.  
  19. int emptySpaces = 3;
  20.  
  21. void setup() {
  22.   Serial.begin(9600);
  23.   pinMode(p1Pin, INPUT);
  24.   pinMode(p2Pin, INPUT);
  25.   pinMode(p3Pin, INPUT);
  26.  
  27.   pinMode(p1Red, OUTPUT);
  28.   pinMode(p2Red, OUTPUT);
  29.   pinMode(p3Red, OUTPUT);
  30.   pinMode(p1Green, OUTPUT);
  31.   pinMode(p1Green, OUTPUT);
  32.   pinMode(p1Green, OUTPUT);
  33.  
  34.   // Car Park No.1 LED Control
  35.   digitalWrite(p1Green, 1);
  36.   digitalWrite(p1Red, 0);
  37.  
  38.   // Car Park No.2 LED Control
  39.   digitalWrite(p2Green, 1);
  40.   digitalWrite(p2Red, 0);
  41.  
  42.   // Car Park No.3 LED Control
  43.   digitalWrite(p3Green, 1);
  44.   digitalWrite(p3Red, 0);
  45.  
  46.  
  47.  
  48. }
  49.  
  50.  
  51. void loop() {
  52.  
  53.   p1Status = digitalRead(p1Pin);
  54.   p2Status = digitalRead(p2Pin);
  55.   p3Status = digitalRead(p3Pin);
  56.   /*Serial.print(p1Status);
  57.     Serial.print(p2Status);
  58.     Serial.println(p3Status);*/
  59.  
  60.  
  61.   /////////////////////////////////////////////////////////////// 2 SPACES LEFT OPEN
  62.   if (p1Status == 1 && p2Status == 0 && p3Status == 0) {
  63.     emptySpaces = 2;
  64.     // Car Park No.1 LED Control
  65.     digitalWrite(p1Green, 0);
  66.     digitalWrite(p1Red, 1);
  67.  
  68.     // Car Park No.2 LED Control
  69.     digitalWrite(p2Green, 1);
  70.     digitalWrite(p2Red, 0);
  71.  
  72.     // Car Park No.3 LED Control
  73.     digitalWrite(p3Green, 1);
  74.     digitalWrite(p3Red, 0);
  75.  
  76.     //Show 2 on screen
  77.     //Send 2 to Nodemcu
  78.   }
  79.   else if (p1Status == 0 && p2Status == 1 && p3Status == 0) {
  80.     emptySpaces = 2;
  81.     // Car Park No.1 LED Control
  82.     digitalWrite(p1Green, 1);
  83.     digitalWrite(p1Red, 0);
  84.  
  85.     // Car Park No.2 LED Control
  86.     digitalWrite(p2Green, 0);
  87.     digitalWrite(p2Red, 1);
  88.  
  89.     // Car Park No.3 LED Control
  90.     digitalWrite(p3Green, 1);
  91.     digitalWrite(p3Red, 0);
  92.  
  93.     //Show 2 on screen
  94.     //Send 2 to Nodemcu
  95.   }
  96.   else if (p1Status == 0 && p2Status == 0 && p3Status == 1) {
  97.     emptySpaces = 2;
  98.     // Car Park No.1 LED Control
  99.     digitalWrite(p1Green, 1);
  100.     digitalWrite(p1Red, 0);
  101.  
  102.     // Car Park No.2 LED Control
  103.     digitalWrite(p2Green, 1);
  104.     digitalWrite(p2Red, 0);
  105.  
  106.     // Car Park No.3 LED Control
  107.     digitalWrite(p3Green, 0);
  108.     digitalWrite(p3Red, 1);
  109.  
  110.     //Show 2 on screen
  111.     //Send 2 to Nodemcu
  112.   }
  113.   //////////////////////////////////////////////////////////////////////////
  114.  
  115.   /////////////////////////////////////////////////////////////// 1 SPACES LEFT OPEN
  116.   else if (p1Status == 1 && p2Status == 1 && p3Status == 0) {
  117.     emptySpaces = 1;
  118.     // Car Park No.1 LED Control
  119.     digitalWrite(p1Green, 0);
  120.     digitalWrite(p1Red, 1);
  121.  
  122.     // Car Park No.2 LED Control
  123.     digitalWrite(p2Green, 0);
  124.     digitalWrite(p2Red, 1);
  125.  
  126.     // Car Park No.3 LED Control
  127.     digitalWrite(p3Green, 1);
  128.     digitalWrite(p3Red, 0);
  129.  
  130.     //Show 1 on screen
  131.     //Send 1 to Nodemcu
  132.   }
  133.   else if (p1Status == 1 && p2Status == 0 && p3Status == 1) {
  134.     emptySpaces = 1;
  135.     // Car Park No.1 LED Control
  136.     digitalWrite(p1Green, 0);
  137.     digitalWrite(p1Red, 1);
  138.  
  139.     // Car Park No.2 LED Control
  140.     digitalWrite(p2Green, 1);
  141.     digitalWrite(p2Red, 0);
  142.  
  143.     // Car Park No.3 LED Control
  144.     digitalWrite(p3Green, 0);
  145.     digitalWrite(p3Red, 1);
  146.  
  147.     //Show 1 on screen
  148.     //Send 1 to Nodemcu
  149.   }
  150.   else if (p1Status == 0 && p2Status == 1 && p3Status == 1) {
  151.     emptySpaces = 1;
  152.     // Car Park No.1 LED Control
  153.     digitalWrite(p1Green, 1);
  154.     digitalWrite(p1Red, 0);
  155.  
  156.     // Car Park No.2 LED Control
  157.     digitalWrite(p2Green, 0);
  158.     digitalWrite(p2Red, 1);
  159.  
  160.     // Car Park No.3 LED Control
  161.     digitalWrite(p3Green, 0);
  162.     digitalWrite(p3Red, 1);
  163.  
  164.     //Show 1 on screen
  165.     //Send 1 to Nodemcu
  166.   }
  167.   //////////////////////////////////////////////////////////////////////////
  168.  
  169.   /////////////////////////////////////////////////////////////// 0 SPACES LEFT OPEN
  170.   else if (p1Status == 1 && p2Status == 1 && p3Status == 1) {
  171.     emptySpaces = 0;
  172.     // Car Park No.1 LED Control
  173.     digitalWrite(p1Green, 0);
  174.     digitalWrite(p1Red, 1);
  175.  
  176.     // Car Park No.2 LED Control
  177.     digitalWrite(p2Green, 0);
  178.     digitalWrite(p2Red, 1);
  179.  
  180.     // Car Park No.3 LED Control
  181.     digitalWrite(p3Green, 0);
  182.     digitalWrite(p3Red, 1);
  183.  
  184.     //Show 0 on screen
  185.     //Send 0 to Nodemcu
  186.   }
  187.   //////////////////////////////////////////////////////////////////////////
  188.  
  189.   /////////////////////////////////////////////////////////////// 3 SPACES LEFT OPEN
  190.   else if (p1Status == 0 && p2Status == 0 && p3Status == 0) {
  191.     emptySpaces = 3;
  192.     // Car Park No.1 LED Control
  193.     digitalWrite(p1Green, 1);
  194.     digitalWrite(p1Red, 0);
  195.  
  196.     // Car Park No.2 LED Control
  197.     digitalWrite(p2Green, 1);
  198.     digitalWrite(p2Red, 0);
  199.  
  200.     // Car Park No.3 LED Control
  201.     digitalWrite(p3Green, 1);
  202.     digitalWrite(p3Red, 0);
  203.  
  204.     //Show 3 on screen
  205.     //Send 3 to Nodemcu
  206.   }
  207.  
  208.  
  209. }
RAW Paste Data