SHARE
TWEET

Untitled

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