Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 3.34 KB | None | 0 0
  1. // Shane Williams
  2. // July 16, 2017
  3. // Parking Lot Program
  4.  
  5.  
  6. #include <Servo.h>  // Arduino Servo Library
  7.  
  8. Servo exitBar;     // create servo object to control a servo
  9.  
  10. int ServoM = 12;        // connected to the servo motor
  11. int Bright = 11;        // servo library disable PWM on pins 9 and 10
  12. int Exit = 9;           // pin connected to the Exit button
  13. int In = 8;             // pin connected to the motion detector to update the display
  14.  
  15. int BarLow = 177;       // lowered position of the bar
  16. int BarUp = 95;         // raised position of the bar
  17. int INTEN = 80;         // led display brightness
  18. int pirState = LOW;     // motion detector starts with no motion detected
  19. int pirVal = 0;         // motion detector pin status
  20. int buttonVal = 0;      // exit button pin status
  21.  
  22. // Pins conections to segments (cathodes).
  23. int segA = 0;
  24. int segB = 1;
  25. int segC = 2;
  26. int segD = 3;
  27. int segE = 4;
  28. int segF = 5;
  29. int segG = 6;
  30.  
  31. // Array with the segments to represent the decimal numbers (0-9)
  32. byte segments[10] = {
  33. // each set represents a number on the 7 segment display
  34.   B00111111, // number 0
  35.   B00000110, // number 1
  36.   B01011011, // number 2
  37.   B01001111, // number 3
  38.   B01100110, // number 4
  39.   B01101101, // number 5
  40.   B01111101, // number 6
  41.   B00000111, // number 7
  42.   B01111111, // number 8
  43.   B01101111  // number 9
  44. };
  45.  
  46. void setup(){
  47.   exitBar.attach(ServoM);       // attaches the servo.
  48.  
  49.   pinMode(Exit, INPUT);         // set Exit connection to Input
  50.   pinMode(In, INPUT);           // set In connection to Input
  51.   digitalWrite(Exit, HIGH);     // Connect Pull-Up resistor
  52.   digitalWrite(In, HIGH);       // Connect Pull-Up resistor
  53.   pinMode(segA,OUTPUT);
  54.   pinMode(segB,OUTPUT);
  55.   pinMode(segC,OUTPUT);
  56.   pinMode(segD,OUTPUT);
  57.   pinMode(segE,OUTPUT);
  58.   pinMode(segF,OUTPUT);
  59.   pinMode(segG,OUTPUT);
  60.   pinMode(Bright,OUTPUT);
  61.   analogWrite(Bright,255*INTEN/100);
  62.   exitBar.write(BarLow);        // Start with the bar in the low position
  63. //  delay(1000);
  64. }
  65.  
  66. int  Available = 9;                 // Number of parking spots available
  67.  
  68. void loop(){
  69.     pirVal = digitalRead(In);   // reads motion detector status
  70.     Display(Available);         // displays number of parking spaces available
  71.     if(pirVal == HIGH) {        // if motion detector status is high(if motion has been triggered)...
  72.         if(Available != 0) {    // if there are still spots available...
  73.         Available--;            // decrease the amount of available spots by 1
  74.         delay(2000);            // wait 2 seconds
  75.         }
  76.      }
  77.     buttonVal = digitalRead(Exit);  // reads exit button status
  78.     if(buttonVal = HIGH) {          // if exit button has been pressed...
  79.         if(Available != 9) {        // if there are less than 9 spots available(9 would mean there is no one in the parking lot to press the button)...
  80.         Available++;                // increase the amount of available spots by 1
  81.         exitBar.write(BarUp);       // raise the flow bar
  82.         delay(3000);                // wait 3 seconds
  83.         exitBar.write(BarLow);      // lower the flow bar
  84.         }
  85.     }
  86. }
  87.  
  88. // writes a number to the display
  89. void Display(int number){
  90.     byte segs =  ~segments[number];    
  91.  
  92.     digitalWrite(segA, bitRead(segs, 0));
  93.     digitalWrite(segB, bitRead(segs, 1));
  94.     digitalWrite(segC, bitRead(segs, 2));
  95.     digitalWrite(segD, bitRead(segs, 3));
  96.     digitalWrite(segE, bitRead(segs, 4));
  97.     digitalWrite(segF, bitRead(segs, 5));
  98.     digitalWrite(segG, bitRead(segs, 6));
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement