![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Reverse Parking Sensor
Dependencies: N5110 PowerControl SRF02 beep mbed
main.h@1:473744047b0f, 2015-05-11 (annotated)
- Committer:
- 200809780
- Date:
- Mon May 11 18:10:40 2015 +0000
- Revision:
- 1:473744047b0f
- Parent:
- 0:f1120add03a8
final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
200809780 | 0:f1120add03a8 | 1 | /** |
200809780 | 0:f1120add03a8 | 2 | @file main.h |
200809780 | 0:f1120add03a8 | 3 | @brief Header file containing functions prototypes, defines and global variables. |
200809780 | 0:f1120add03a8 | 4 | @brief Reverse Parking Sensor |
200809780 | 0:f1120add03a8 | 5 | @author Andreas Konstantinou |
200809780 | 0:f1120add03a8 | 6 | @date April 2015 |
200809780 | 0:f1120add03a8 | 7 | */ |
200809780 | 0:f1120add03a8 | 8 | |
200809780 | 0:f1120add03a8 | 9 | #ifndef MAIN_H |
200809780 | 0:f1120add03a8 | 10 | #define MAIN_H |
200809780 | 0:f1120add03a8 | 11 | #include "mbed.h" |
200809780 | 0:f1120add03a8 | 12 | #include "N5110.h" |
200809780 | 0:f1120add03a8 | 13 | #include "SRF02.h" |
200809780 | 0:f1120add03a8 | 14 | #include "beep.h" |
200809780 | 0:f1120add03a8 | 15 | #include "PowerControl/PowerControl.h" |
200809780 | 0:f1120add03a8 | 16 | #include "PowerControl/EthernetPowerControl.h" |
200809780 | 0:f1120add03a8 | 17 | |
200809780 | 0:f1120add03a8 | 18 | #define USR_POWERDOWN (0x140) |
200809780 | 0:f1120add03a8 | 19 | |
200809780 | 0:f1120add03a8 | 20 | /** |
200809780 | 0:f1120add03a8 | 21 | @namespace srf02 |
200809780 | 0:f1120add03a8 | 22 | @brief ultrasonic distance sensor connects to I2C pins SDA and SCL |
200809780 | 0:f1120add03a8 | 23 | */ |
200809780 | 0:f1120add03a8 | 24 | SRF02 srf02(p28,p27); |
200809780 | 0:f1120add03a8 | 25 | |
200809780 | 0:f1120add03a8 | 26 | |
200809780 | 0:f1120add03a8 | 27 | /** |
200809780 | 0:f1120add03a8 | 28 | @namespace leds |
200809780 | 0:f1120add03a8 | 29 | @brief The four LEDs on mbed |
200809780 | 0:f1120add03a8 | 30 | */ |
200809780 | 0:f1120add03a8 | 31 | BusOut leds(LED4, LED3, LED2, LED1); |
200809780 | 0:f1120add03a8 | 32 | |
200809780 | 0:f1120add03a8 | 33 | /** |
200809780 | 0:f1120add03a8 | 34 | @namespace lcd |
200809780 | 0:f1120add03a8 | 35 | @brief NOKIA 5110 LCD display |
200809780 | 0:f1120add03a8 | 36 | */ |
200809780 | 0:f1120add03a8 | 37 | N5110 lcd(p7,p8, p9, p10,p11, p13,p26); //vcc,sce,rst,dc,mosi,clk,led |
200809780 | 0:f1120add03a8 | 38 | /** |
200809780 | 0:f1120add03a8 | 39 | @namespace buzzer |
200809780 | 0:f1120add03a8 | 40 | @brief a piezo buzzer connected to PWM pin |
200809780 | 0:f1120add03a8 | 41 | */ |
200809780 | 0:f1120add03a8 | 42 | Beep buzzer(p21); |
200809780 | 0:f1120add03a8 | 43 | |
200809780 | 0:f1120add03a8 | 44 | /** |
200809780 | 0:f1120add03a8 | 45 | @namespace led_red |
200809780 | 0:f1120add03a8 | 46 | @brief Red led connected to PWM pin for brightness |
200809780 | 0:f1120add03a8 | 47 | */ |
200809780 | 0:f1120add03a8 | 48 | DigitalOut led_red(p24); |
200809780 | 0:f1120add03a8 | 49 | |
200809780 | 0:f1120add03a8 | 50 | /** |
200809780 | 0:f1120add03a8 | 51 | @namespace led_yellow |
200809780 | 0:f1120add03a8 | 52 | @brief Yellowonnected to PWM pin for brightness |
200809780 | 0:f1120add03a8 | 53 | */ |
200809780 | 0:f1120add03a8 | 54 | DigitalOut led_yellow(p23); |
200809780 | 0:f1120add03a8 | 55 | |
200809780 | 0:f1120add03a8 | 56 | /** |
200809780 | 0:f1120add03a8 | 57 | @namespace led_green |
200809780 | 0:f1120add03a8 | 58 | @brief Green led connected to PWM pin for brightness |
200809780 | 0:f1120add03a8 | 59 | */ |
200809780 | 0:f1120add03a8 | 60 | DigitalOut led_green(p22); |
200809780 | 0:f1120add03a8 | 61 | |
200809780 | 0:f1120add03a8 | 62 | /** |
200809780 | 0:f1120add03a8 | 63 | @namespace ain2 |
200809780 | 0:f1120add03a8 | 64 | @brief Analog input for the potentiometer to control the frequency of the buzzer |
200809780 | 0:f1120add03a8 | 65 | */ |
200809780 | 0:f1120add03a8 | 66 | AnalogIn ain2(p20); |
200809780 | 0:f1120add03a8 | 67 | |
200809780 | 0:f1120add03a8 | 68 | /** |
200809780 | 0:f1120add03a8 | 69 | @namespace ain1 |
200809780 | 0:f1120add03a8 | 70 | @brief Analog input for the potentiometer to control the brightness of the lcd |
200809780 | 0:f1120add03a8 | 71 | */ |
200809780 | 0:f1120add03a8 | 72 | AnalogIn ain1(p19); |
200809780 | 0:f1120add03a8 | 73 | |
200809780 | 0:f1120add03a8 | 74 | /** |
200809780 | 0:f1120add03a8 | 75 | @namespace button_1 |
200809780 | 0:f1120add03a8 | 76 | @brief Set button_1 to be interrupt, coonected to GPIO |
200809780 | 0:f1120add03a8 | 77 | */ |
200809780 | 0:f1120add03a8 | 78 | InterruptIn button_1(p17); |
200809780 | 0:f1120add03a8 | 79 | |
200809780 | 0:f1120add03a8 | 80 | /** |
200809780 | 0:f1120add03a8 | 81 | @namespace button_2 |
200809780 | 0:f1120add03a8 | 82 | @brief set button_2 to be interrupt, coonected to GPIO |
200809780 | 0:f1120add03a8 | 83 | */ |
200809780 | 0:f1120add03a8 | 84 | InterruptIn button_2(p18); |
200809780 | 0:f1120add03a8 | 85 | |
200809780 | 0:f1120add03a8 | 86 | /** |
200809780 | 0:f1120add03a8 | 87 | @namespace button_3 |
200809780 | 0:f1120add03a8 | 88 | @brief set button_3 to be interrupt, coonected to GPIO |
200809780 | 0:f1120add03a8 | 89 | */ |
200809780 | 0:f1120add03a8 | 90 | |
200809780 | 0:f1120add03a8 | 91 | InterruptIn button_3(p16); |
200809780 | 0:f1120add03a8 | 92 | |
200809780 | 0:f1120add03a8 | 93 | /** |
200809780 | 0:f1120add03a8 | 94 | @namespace button_4 |
200809780 | 0:f1120add03a8 | 95 | @brief set button_4 to be interrupt, coonected to GPIO |
200809780 | 0:f1120add03a8 | 96 | */ |
200809780 | 0:f1120add03a8 | 97 | InterruptIn button_4(p15); |
200809780 | 0:f1120add03a8 | 98 | |
200809780 | 0:f1120add03a8 | 99 | /** |
200809780 | 0:f1120add03a8 | 100 | @namespace timer_red |
200809780 | 0:f1120add03a8 | 101 | @brief ticker object used to control the time of red LED |
200809780 | 0:f1120add03a8 | 102 | */ |
200809780 | 0:f1120add03a8 | 103 | Ticker timer_red; |
200809780 | 0:f1120add03a8 | 104 | |
200809780 | 0:f1120add03a8 | 105 | /** |
200809780 | 0:f1120add03a8 | 106 | @namespace timer_yellow |
200809780 | 0:f1120add03a8 | 107 | @brief ticker object used to control the time of yellow LED |
200809780 | 0:f1120add03a8 | 108 | */ |
200809780 | 0:f1120add03a8 | 109 | Ticker timer_yellow; |
200809780 | 0:f1120add03a8 | 110 | |
200809780 | 0:f1120add03a8 | 111 | /** |
200809780 | 0:f1120add03a8 | 112 | @namespace timer_green |
200809780 | 0:f1120add03a8 | 113 | @brief ticker object used to control the time of green LED |
200809780 | 0:f1120add03a8 | 114 | */ |
200809780 | 0:f1120add03a8 | 115 | Ticker timer_green; |
200809780 | 0:f1120add03a8 | 116 | |
200809780 | 0:f1120add03a8 | 117 | /** Get Avegare distance |
200809780 | 0:f1120add03a8 | 118 | * |
200809780 | 0:f1120add03a8 | 119 | * This function gets the avegare distance of 5 values of the sensor |
200809780 | 0:f1120add03a8 | 120 | */ |
200809780 | 0:f1120add03a8 | 121 | void Get_Average(); |
200809780 | 0:f1120add03a8 | 122 | |
200809780 | 0:f1120add03a8 | 123 | /** Timer Expired red led |
200809780 | 0:f1120add03a8 | 124 | * |
200809780 | 0:f1120add03a8 | 125 | * This function sets the flag of the red led to high |
200809780 | 0:f1120add03a8 | 126 | */ |
200809780 | 0:f1120add03a8 | 127 | void timerExpired_red(); |
200809780 | 0:f1120add03a8 | 128 | |
200809780 | 1:473744047b0f | 129 | /** Button1 Pressed |
200809780 | 1:473744047b0f | 130 | * |
200809780 | 1:473744047b0f | 131 | * This function sets the flag of button 1 to high |
200809780 | 1:473744047b0f | 132 | */ |
200809780 | 1:473744047b0f | 133 | void button1_Pressed(); |
200809780 | 1:473744047b0f | 134 | |
200809780 | 1:473744047b0f | 135 | /** Button2 Pressed |
200809780 | 1:473744047b0f | 136 | * |
200809780 | 1:473744047b0f | 137 | * This function sets the flag of button 2 to high |
200809780 | 1:473744047b0f | 138 | */ |
200809780 | 1:473744047b0f | 139 | void button2_Pressed(); |
200809780 | 1:473744047b0f | 140 | |
200809780 | 1:473744047b0f | 141 | /** Button3 Pressed |
200809780 | 1:473744047b0f | 142 | * |
200809780 | 1:473744047b0f | 143 | * This function sets the flag of button 3 to high |
200809780 | 1:473744047b0f | 144 | */ |
200809780 | 1:473744047b0f | 145 | void button3_Pressed(); |
200809780 | 1:473744047b0f | 146 | |
200809780 | 1:473744047b0f | 147 | /** Button4 Pressed |
200809780 | 1:473744047b0f | 148 | * |
200809780 | 1:473744047b0f | 149 | * This function sets the flag of button 4 to high |
200809780 | 1:473744047b0f | 150 | */ |
200809780 | 1:473744047b0f | 151 | void button4_Pressed(); |
200809780 | 1:473744047b0f | 152 | |
200809780 | 0:f1120add03a8 | 153 | /** Timer Expired yellow led |
200809780 | 0:f1120add03a8 | 154 | * |
200809780 | 0:f1120add03a8 | 155 | * This function sets the flag of the yellow led to high |
200809780 | 0:f1120add03a8 | 156 | */ |
200809780 | 0:f1120add03a8 | 157 | void timerExpired_yellow(); |
200809780 | 0:f1120add03a8 | 158 | |
200809780 | 0:f1120add03a8 | 159 | /** Timer Expired green led |
200809780 | 0:f1120add03a8 | 160 | * |
200809780 | 0:f1120add03a8 | 161 | * This function sets the flag of the green led to high |
200809780 | 0:f1120add03a8 | 162 | */ |
200809780 | 0:f1120add03a8 | 163 | void timerExpired_green(); |
200809780 | 0:f1120add03a8 | 164 | |
200809780 | 0:f1120add03a8 | 165 | /** Check states of the buttons |
200809780 | 0:f1120add03a8 | 166 | * |
200809780 | 0:f1120add03a8 | 167 | * This function checks the status between the buttons 2, 3, and 4 and based on the status of each one then executes the appropiate process |
200809780 | 0:f1120add03a8 | 168 | */ |
200809780 | 0:f1120add03a8 | 169 | void ButtonsOperation(); |
200809780 | 0:f1120add03a8 | 170 | |
200809780 | 0:f1120add03a8 | 171 | /** Check state of button 1 |
200809780 | 0:f1120add03a8 | 172 | * |
200809780 | 0:f1120add03a8 | 173 | * This function checks the state of the button 1. if button1 is pressed then |
200809780 | 0:f1120add03a8 | 174 | * the leds and buzzer start blinking and making sound,repsectively, based on the measurements of the sensor |
200809780 | 0:f1120add03a8 | 175 | */ |
200809780 | 0:f1120add03a8 | 176 | void buttonOperation_1(); |
200809780 | 0:f1120add03a8 | 177 | |
200809780 | 0:f1120add03a8 | 178 | /** Check state of button 2 |
200809780 | 0:f1120add03a8 | 179 | * |
200809780 | 0:f1120add03a8 | 180 | * This functions checks the status of the button 2. if it is pressed then converts |
200809780 | 0:f1120add03a8 | 181 | * the units of the sensor's measurements from meters to centimeters and displays them on the lcd |
200809780 | 0:f1120add03a8 | 182 | */ |
200809780 | 0:f1120add03a8 | 183 | void buttonOperation_2(); |
200809780 | 0:f1120add03a8 | 184 | |
200809780 | 0:f1120add03a8 | 185 | /** Check state of button 3 |
200809780 | 0:f1120add03a8 | 186 | * |
200809780 | 0:f1120add03a8 | 187 | * This functions checks the status of the button 3. if it is pressed then a new pattern is showed in the lcd |
200809780 | 0:f1120add03a8 | 188 | * and displays the measured distance. |
200809780 | 0:f1120add03a8 | 189 | */ |
200809780 | 0:f1120add03a8 | 190 | void buttonOperation_3(); |
200809780 | 0:f1120add03a8 | 191 | |
200809780 | 0:f1120add03a8 | 192 | /** Check state of button 4 |
200809780 | 0:f1120add03a8 | 193 | * |
200809780 | 0:f1120add03a8 | 194 | * This functions checks the status of the button 4. if it is pressed then |
200809780 | 0:f1120add03a8 | 195 | * a new pattern is displayed on lcd and displays the sensor's measurements |
200809780 | 0:f1120add03a8 | 196 | */ |
200809780 | 0:f1120add03a8 | 197 | void buttonOperation_4(); |
200809780 | 0:f1120add03a8 | 198 | |
200809780 | 0:f1120add03a8 | 199 | /** Print Current Time and Date |
200809780 | 0:f1120add03a8 | 200 | * |
200809780 | 0:f1120add03a8 | 201 | * This function sets the current time and date and prints them on the dispaly |
200809780 | 0:f1120add03a8 | 202 | */ |
200809780 | 0:f1120add03a8 | 203 | void Print_Time_Date(); |
200809780 | 0:f1120add03a8 | 204 | |
200809780 | 0:f1120add03a8 | 205 | int timerflag_red = 0; /*!< timer flag red LED set in ISR */ |
200809780 | 0:f1120add03a8 | 206 | int timerflag_yellow = 0;/*!< timer flag yellow LED set in ISR */ |
200809780 | 0:f1120add03a8 | 207 | int timerflag_green = 0;/*!< timer flag green LED set in ISR */ |
200809780 | 0:f1120add03a8 | 208 | int setTimeFlag = 0;/*!< time flag set in ISR */ |
200809780 | 0:f1120add03a8 | 209 | int button1_flag=0; /*!< button 1 flag set in ISR */ |
200809780 | 0:f1120add03a8 | 210 | int button2_flag=0;/*!< button 2 flag set in ISR */ |
200809780 | 0:f1120add03a8 | 211 | int button3_flag=0;/*!< button 3 flag set in ISR */ |
200809780 | 0:f1120add03a8 | 212 | int button4_flag=0;/*!< button 4 flag set in ISR */ |
200809780 | 0:f1120add03a8 | 213 | char buffer[5]; /*!< buffer used to display characters on lcd, each character is 6 pixels wide, screen is 84 pixels (84/6 = 14maximum)*/ |
200809780 | 0:f1120add03a8 | 214 | float a1;/*!< a1 used to control the brightness of the LED background display by getting the value of the potentiometer1 */ |
200809780 | 0:f1120add03a8 | 215 | float a2;/*!< a2 used to control the frequency of the buzzer by getting the value of the potentiometer2*/ |
200809780 | 0:f1120add03a8 | 216 | float distance=0;/*!<this global variable used to get the average of 5 values of sensor */ |
200809780 | 0:f1120add03a8 | 217 | float Distance_Array[5]; /*!< Distance_Array used to store 5 values of the sensor*/ |
200809780 | 0:f1120add03a8 | 218 | |
200809780 | 0:f1120add03a8 | 219 | #endif |