garage

Dependencies:   Servo HCSR04

Committer:
kefil_tonouewa
Date:
Mon Mar 08 18:48:34 2021 +0000
Revision:
0:d05b3ce87bb4
my program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kefil_tonouewa 0:d05b3ce87bb4 1 #include "mbed.h"
kefil_tonouewa 0:d05b3ce87bb4 2 #include "HCSR04.h"
kefil_tonouewa 0:d05b3ce87bb4 3 #include "Servo.h"
kefil_tonouewa 0:d05b3ce87bb4 4
kefil_tonouewa 0:d05b3ce87bb4 5 #define PARKING_SPACE_TOTAL 100
kefil_tonouewa 0:d05b3ce87bb4 6
kefil_tonouewa 0:d05b3ce87bb4 7 //Light Pin Assignment
kefil_tonouewa 0:d05b3ce87bb4 8 #define RED_1_PIN D6
kefil_tonouewa 0:d05b3ce87bb4 9 #define RED_2_PIN D7
kefil_tonouewa 0:d05b3ce87bb4 10 #define GREEN_1_PIN D8
kefil_tonouewa 0:d05b3ce87bb4 11 #define GREEN_2_PIN D9
kefil_tonouewa 0:d05b3ce87bb4 12
kefil_tonouewa 0:d05b3ce87bb4 13 //Piezo Speaker Pin Assignment
kefil_tonouewa 0:d05b3ce87bb4 14 #define PIEZO_BUZZER_1_PIN D3
kefil_tonouewa 0:d05b3ce87bb4 15 #define PIEZO_BUZZER_2_PIN D11
kefil_tonouewa 0:d05b3ce87bb4 16
kefil_tonouewa 0:d05b3ce87bb4 17 //Servo Motor Pin Assignment
kefil_tonouewa 0:d05b3ce87bb4 18 #define SERVO_MOTOR_1_PIN PTA1
kefil_tonouewa 0:d05b3ce87bb4 19 //#define SERVO_MOTOR_2_PIN D10
kefil_tonouewa 0:d05b3ce87bb4 20
kefil_tonouewa 0:d05b3ce87bb4 21 //Ultrasonic Sensor Pin Assignment
kefil_tonouewa 0:d05b3ce87bb4 22 #define ECHO_1_PIN D0
kefil_tonouewa 0:d05b3ce87bb4 23 #define TRIGGER_1_PIN D1
kefil_tonouewa 0:d05b3ce87bb4 24 #define ECHO_2_PIN D4
kefil_tonouewa 0:d05b3ce87bb4 25 #define TRIGGER_2_PIN D5
kefil_tonouewa 0:d05b3ce87bb4 26
kefil_tonouewa 0:d05b3ce87bb4 27 //Pressure Sensor Pin Assignement
kefil_tonouewa 0:d05b3ce87bb4 28 #define PRESSURE_1_PIN A0
kefil_tonouewa 0:d05b3ce87bb4 29 #define PRESSURE_2_PIN A1
kefil_tonouewa 0:d05b3ce87bb4 30 #define VCC 5.00
kefil_tonouewa 0:d05b3ce87bb4 31 #define R_DIV 3230.0
kefil_tonouewa 0:d05b3ce87bb4 32
kefil_tonouewa 0:d05b3ce87bb4 33 //LCD Pin Assignment
kefil_tonouewa 0:d05b3ce87bb4 34
kefil_tonouewa 0:d05b3ce87bb4 35 //Setting up the lights as output
kefil_tonouewa 0:d05b3ce87bb4 36 DigitalOut RED_LIGHT_1(RED_1_PIN);
kefil_tonouewa 0:d05b3ce87bb4 37 DigitalOut RED_LIGHT_2(RED_2_PIN);
kefil_tonouewa 0:d05b3ce87bb4 38 DigitalOut GREEN_LIGHT_1(GREEN_1_PIN);
kefil_tonouewa 0:d05b3ce87bb4 39 DigitalOut GREEN_LIGHT_2(GREEN_2_PIN);
kefil_tonouewa 0:d05b3ce87bb4 40
kefil_tonouewa 0:d05b3ce87bb4 41 //Setting up the Ultrasonic Sensors
kefil_tonouewa 0:d05b3ce87bb4 42 DigitalOut ECHO_1(ECHO_1_PIN);
kefil_tonouewa 0:d05b3ce87bb4 43 DigitalIn TRIGGER_1(TRIGGER_1_PIN);
kefil_tonouewa 0:d05b3ce87bb4 44 DigitalOut ECHO_2(ECHO_2_PIN);
kefil_tonouewa 0:d05b3ce87bb4 45 DigitalIn TRIGGER_2(TRIGGER_2_PIN);
kefil_tonouewa 0:d05b3ce87bb4 46
kefil_tonouewa 0:d05b3ce87bb4 47 //Setting up the Servo Motors
kefil_tonouewa 0:d05b3ce87bb4 48 //DigitalOut SERVO_1(SERVO_MOTOR_1_PIN);
kefil_tonouewa 0:d05b3ce87bb4 49 //DigitalOut SERVO_2(SERVO_MOTOR_2_PIN);
kefil_tonouewa 0:d05b3ce87bb4 50
kefil_tonouewa 0:d05b3ce87bb4 51 //Setting up Piezo Speakers
kefil_tonouewa 0:d05b3ce87bb4 52 DigitalOut PIEZO_1(PIEZO_BUZZER_1_PIN);
kefil_tonouewa 0:d05b3ce87bb4 53 DigitalOut PIEZO_2(PIEZO_BUZZER_2_PIN);
kefil_tonouewa 0:d05b3ce87bb4 54
kefil_tonouewa 0:d05b3ce87bb4 55 //Setting up the Pressure Sensors
kefil_tonouewa 0:d05b3ce87bb4 56 AnalogIn PRESSURE_1 (PRESSURE_1_PIN);
kefil_tonouewa 0:d05b3ce87bb4 57 AnalogIn PRESSURE_2 (PRESSURE_2_PIN);
kefil_tonouewa 0:d05b3ce87bb4 58
kefil_tonouewa 0:d05b3ce87bb4 59 int main()
kefil_tonouewa 0:d05b3ce87bb4 60 {
kefil_tonouewa 0:d05b3ce87bb4 61 /*
kefil_tonouewa 0:d05b3ce87bb4 62 //Car counting variables
kefil_tonouewa 0:d05b3ce87bb4 63 int8_t Car_In = 0;
kefil_tonouewa 0:d05b3ce87bb4 64 int8_t Car_Out = 0;
kefil_tonouewa 0:d05b3ce87bb4 65
kefil_tonouewa 0:d05b3ce87bb4 66 //Setting the red lights to 1
kefil_tonouewa 0:d05b3ce87bb4 67 RED_LIGHT_1 = 1;
kefil_tonouewa 0:d05b3ce87bb4 68 RED_LIGHT_2 = 1;
kefil_tonouewa 0:d05b3ce87bb4 69
kefil_tonouewa 0:d05b3ce87bb4 70 //Setting the green lights to 0
kefil_tonouewa 0:d05b3ce87bb4 71 GREEN_LIGHT_1 = 0;
kefil_tonouewa 0:d05b3ce87bb4 72 GREEN_LIGHT_2 = 0;
kefil_tonouewa 0:d05b3ce87bb4 73
kefil_tonouewa 0:d05b3ce87bb4 74 //Ultrasonic Sensor Stuff
kefil_tonouewa 0:d05b3ce87bb4 75 //If the value fetched from here is less than a certain value
kefil_tonouewa 0:d05b3ce87bb4 76 //Than we know there is an object close to the gate else we
kefil_tonouewa 0:d05b3ce87bb4 77 //don't change anything
kefil_tonouewa 0:d05b3ce87bb4 78 HCSR04 Ultrasonic_1(TRIGGER_1_PIN,ECHO_1_PIN);
kefil_tonouewa 0:d05b3ce87bb4 79 HCSR04 Ultrasonic_2(TRIGGER_2_PIN,ECHO_2_PIN);
kefil_tonouewa 0:d05b3ce87bb4 80 bool isObjectClose_1 = false;
kefil_tonouewa 0:d05b3ce87bb4 81 bool isObjectClose_2 = false;
kefil_tonouewa 0:d05b3ce87bb4 82 uint8_t Distance_1 = 0;
kefil_tonouewa 0:d05b3ce87bb4 83 uint8_t Distance_2 = 0;
kefil_tonouewa 0:d05b3ce87bb4 84
kefil_tonouewa 0:d05b3ce87bb4 85 //Pressure Sensor Stuff
kefil_tonouewa 0:d05b3ce87bb4 86 //If the value fetched from here is greater than a certain value
kefil_tonouewa 0:d05b3ce87bb4 87 //than we know it is a car else we don't change anything
kefil_tonouewa 0:d05b3ce87bb4 88 int Pressure_Sensor_1 = 0;
kefil_tonouewa 0:d05b3ce87bb4 89 float fsrR_1;
kefil_tonouewa 0:d05b3ce87bb4 90 float fsrV_1;
kefil_tonouewa 0:d05b3ce87bb4 91 float fsrG_1;
kefil_tonouewa 0:d05b3ce87bb4 92 float force_1;
kefil_tonouewa 0:d05b3ce87bb4 93 int Pressure_Sensor_2 = 0;
kefil_tonouewa 0:d05b3ce87bb4 94 float fsrR_2;
kefil_tonouewa 0:d05b3ce87bb4 95 float fsrV_2;
kefil_tonouewa 0:d05b3ce87bb4 96 float fsrG_2;
kefil_tonouewa 0:d05b3ce87bb4 97 float force_2;
kefil_tonouewa 0:d05b3ce87bb4 98 bool isCar_1 = false;
kefil_tonouewa 0:d05b3ce87bb4 99 bool isCar_2 = false;
kefil_tonouewa 0:d05b3ce87bb4 100 */
kefil_tonouewa 0:d05b3ce87bb4 101 //Servo Motor Stuff
kefil_tonouewa 0:d05b3ce87bb4 102 Servo entranceGate(PTA1);
kefil_tonouewa 0:d05b3ce87bb4 103 //Servo exitGate(SERVO_MOTOR_2_PIN);
kefil_tonouewa 0:d05b3ce87bb4 104
kefil_tonouewa 0:d05b3ce87bb4 105
kefil_tonouewa 0:d05b3ce87bb4 106
kefil_tonouewa 0:d05b3ce87bb4 107 while(1) {
kefil_tonouewa 0:d05b3ce87bb4 108
kefil_tonouewa 0:d05b3ce87bb4 109 for(float p=0; p<1.0; p += 0.1)
kefil_tonouewa 0:d05b3ce87bb4 110 {
kefil_tonouewa 0:d05b3ce87bb4 111 entranceGate = p;
kefil_tonouewa 0:d05b3ce87bb4 112 wait(0.2);
kefil_tonouewa 0:d05b3ce87bb4 113 }
kefil_tonouewa 0:d05b3ce87bb4 114 }
kefil_tonouewa 0:d05b3ce87bb4 115 }