Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo exitBar; // create servo object to control a servo
- int ServoM = 12; // connected to the servo motor
- int Bright = 11; // servo library disable PWM on pins 9 and 10
- int Exit = 9; // pin connected to the Exit button
- int In = 8; // pin connected to the motion detector to update the display
- int BarLow = 177; // lowered position of the bar
- int BarUp = 95; // raised position of the bar
- int CAPACITY = 9; // capacity of the parking lot
- int INTEN = 80; // display intensity %
- int pirState = LOW; // motion detector starts with no motion detected
- int pirVal = 0; // motion detector pin status
- int buttonVal = 0; // exit button pin status
- //Pins conections to segments (cathodes).
- int segA = 0;
- int segB = 1;
- int segC = 2;
- int segD = 3;
- int segE = 4;
- int segF = 5;
- int segG = 6;
- //Array with the segments to represent the decimal numbers (0-9)
- byte segments[10] = {
- // each set represents a number on the 7 segment display
- B00111111, // number 0
- B00000110, // number 1
- B01011011, // number 2
- B01001111, // number 3
- B01100110, // number 4
- B01101101, // number 5
- B01111101, // number 6
- B00000111, // number 7
- B01111111, // number 8
- B01101111 // number 9
- };
- void setup(){
- exitBar.attach(ServoM); // attaches the servo.
- pinMode(Exit, INPUT); // set Exit connection to Input
- pinMode(In, INPUT); // set In connection to Input
- digitalWrite(Exit, HIGH); // Connect Pull-Up resistor
- digitalWrite(In, HIGH); // Connect Pull-Up resistor
- pinMode(segA,OUTPUT);
- pinMode(segB,OUTPUT);
- pinMode(segC,OUTPUT);
- pinMode(segD,OUTPUT);
- pinMode(segE,OUTPUT);
- pinMode(segF,OUTPUT);
- pinMode(segG,OUTPUT);
- pinMode(Bright,OUTPUT);
- analogWrite(Bright,255*INTEN/100);
- exitBar.write(BarLow); // Start with the bar in the low position
- // delay(1000);
- }
- int Available = 9; // Number of parking spots available
- void loop(){
- pirVal = digitalRead(In); // reads motion detector status
- Display(Available); // displays number of parking spaces available
- if(pirVal == HIGH) // if motion detector status is high(if motion has been triggered)...
- {
- if(Available != 0){ // if there are still spots available...
- Available--; // decrease the amount of available spots by 1
- delay(2000); // wait 2 seconds
- }
- }
- buttonVal = digitalRead(Exit); // reads exit button status
- if(buttonVal = HIGH) // if exit button has been pressed...
- {
- 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)...
- Available++; // increase the amount of available spots by 1
- exitBar.write(BarUp); // raise the flow bar
- delay(3000); // wait 3 seconds
- exitBar.write(BarLow); // lower the flow bar
- }
- }
- }
- /*-------------------------------------------------------------------
- Put the segments according to the number.
- --------------------------------------------------------------------*/
- void Display(int number){
- byte segs = ~segments[number]; //"~" is used for common anode.
- digitalWrite(segA, bitRead(segs, 0));
- digitalWrite(segB, bitRead(segs, 1));
- digitalWrite(segC, bitRead(segs, 2));
- digitalWrite(segD, bitRead(segs, 3));
- digitalWrite(segE, bitRead(segs, 4));
- digitalWrite(segF, bitRead(segs, 5));
- digitalWrite(segG, bitRead(segs, 6));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement