Reverse Parking sensor
Dependencies: N5110 SRF02 buzzer mbed
Fork of ParkingSENSOR by
main.h@1:775f6e8071a2, 2016-05-05 (annotated)
- Committer:
- Reniboy
- Date:
- Thu May 05 02:08:46 2016 +0000
- Revision:
- 1:775f6e8071a2
- Parent:
- 0:e1ae1b9889a3
- Child:
- 3:68cabac00547
Revison 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Reniboy | 0:e1ae1b9889a3 | 1 | /** |
Reniboy | 0:e1ae1b9889a3 | 2 | @file main.h |
Reniboy | 0:e1ae1b9889a3 | 3 | @brief Header file containg functions, variables and prototypes |
Reniboy | 0:e1ae1b9889a3 | 4 | @brief Revision 1.0 |
Reniboy | 0:e1ae1b9889a3 | 5 | @brief Reverse Parking sensor |
Reniboy | 1:775f6e8071a2 | 6 | @Author Renosi Momoh |
Reniboy | 1:775f6e8071a2 | 7 | @date March 2015 |
Reniboy | 1:775f6e8071a2 | 8 | **/ |
Reniboy | 0:e1ae1b9889a3 | 9 | |
Reniboy | 0:e1ae1b9889a3 | 10 | |
Reniboy | 0:e1ae1b9889a3 | 11 | #include "mbed.h" |
Reniboy | 0:e1ae1b9889a3 | 12 | #include "N5110.h" |
Reniboy | 0:e1ae1b9889a3 | 13 | #include "SRF02/SRF02.h" |
Reniboy | 0:e1ae1b9889a3 | 14 | #include "buzzer.h" |
Reniboy | 1:775f6e8071a2 | 15 | |
Reniboy | 0:e1ae1b9889a3 | 16 | |
Reniboy | 0:e1ae1b9889a3 | 17 | /** INPUTS AND OUTPUTS **/ |
Reniboy | 0:e1ae1b9889a3 | 18 | |
Reniboy | 0:e1ae1b9889a3 | 19 | N5110 lcd (PTE26, PTA0, PTC4, PTD0, PTD2, PTD1, PTC3); |
Reniboy | 1:775f6e8071a2 | 20 | /** |
Reniboy | 1:775f6e8071a2 | 21 | @namespace LCD display |
Reniboy | 1:775f6e8071a2 | 22 | @brief Connections for the LCD Display |
Reniboy | 1:775f6e8071a2 | 23 | **/ |
Reniboy | 0:e1ae1b9889a3 | 24 | SRF02 sensor(I2C_SDA,I2C_SCL); |
Reniboy | 1:775f6e8071a2 | 25 | /** |
Reniboy | 1:775f6e8071a2 | 26 | @namespace Ultrasonic sensor connected in I2C mode |
Reniboy | 1:775f6e8071a2 | 27 | @brief Ultrasonic distance sensor connected in I2C mode |
Reniboy | 1:775f6e8071a2 | 28 | **/ |
Reniboy | 0:e1ae1b9889a3 | 29 | Beep buzzer(PTA2); |
Reniboy | 0:e1ae1b9889a3 | 30 | /** |
Reniboy | 1:775f6e8071a2 | 31 | @namespace Buzzer |
Reniboy | 0:e1ae1b9889a3 | 32 | @brief Piezo type buzzer that can produce notes and vary the frequency as well. Connected to Pwm signal |
Reniboy | 0:e1ae1b9889a3 | 33 | **/ |
Reniboy | 0:e1ae1b9889a3 | 34 | |
Reniboy | 0:e1ae1b9889a3 | 35 | InterruptIn button(PTB18); |
Reniboy | 0:e1ae1b9889a3 | 36 | /** |
Reniboy | 0:e1ae1b9889a3 | 37 | @Brief Button connected to mbed with the use of InterruptIn class**/ |
Reniboy | 0:e1ae1b9889a3 | 38 | InterruptIn sw2(SW2); |
Reniboy | 1:775f6e8071a2 | 39 | /** |
Reniboy | 1:775f6e8071a2 | 40 | @namespace SW2 button |
Reniboy | 1:775f6e8071a2 | 41 | @brief DigitalIn button |
Reniboy | 1:775f6e8071a2 | 42 | **/ |
Reniboy | 0:e1ae1b9889a3 | 43 | InterruptIn sw3(SW3); |
Reniboy | 0:e1ae1b9889a3 | 44 | |
Reniboy | 0:e1ae1b9889a3 | 45 | /** |
Reniboy | 1:775f6e8071a2 | 46 | @namespace SW3 button |
Reniboy | 1:775f6e8071a2 | 47 | @brief DigitalIn button |
Reniboy | 0:e1ae1b9889a3 | 48 | **/ |
Reniboy | 0:e1ae1b9889a3 | 49 | |
Reniboy | 1:775f6e8071a2 | 50 | DigitalOut r_led(PTC2); |
Reniboy | 1:775f6e8071a2 | 51 | /** |
Reniboy | 1:775f6e8071a2 | 52 | @namespace Led |
Reniboy | 1:775f6e8071a2 | 53 | @brief Changes color depending on distance |
Reniboy | 1:775f6e8071a2 | 54 | **/ |
Reniboy | 1:775f6e8071a2 | 55 | Serial serial(USBTX, USBRX); |
Reniboy | 1:775f6e8071a2 | 56 | /** |
Reniboy | 1:775f6e8071a2 | 57 | @Namespace USB connections |
Reniboy | 1:775f6e8071a2 | 58 | @brief Used for programming the sensor |
Reniboy | 1:775f6e8071a2 | 59 | **/ |
Reniboy | 1:775f6e8071a2 | 60 | AnalogIn pot(PTB2); |
Reniboy | 1:775f6e8071a2 | 61 | /** |
Reniboy | 1:775f6e8071a2 | 62 | @namespace AnalogIn potentiometer |
Reniboy | 1:775f6e8071a2 | 63 | @brief Potentiometer middle pin connected to PTB3, other two ends connected to GND and 3.3V |
Reniboy | 1:775f6e8071a2 | 64 | **/ |
Reniboy | 0:e1ae1b9889a3 | 65 | |
Reniboy | 1:775f6e8071a2 | 66 | /** Ticker, flags and Interrupt Service Routines**/ |
Reniboy | 0:e1ae1b9889a3 | 67 | |
Reniboy | 1:775f6e8071a2 | 68 | Ticker ticker; //*!< Objects to create tickers for parking sensor in cm */ |
Reniboy | 1:775f6e8071a2 | 69 | Ticker ticker2; //*!< Objects to create tickers for radar parking sensor mode */ |
Reniboy | 1:775f6e8071a2 | 70 | Ticker ticker3; //*!< Ticker to call interrupt for parking sensor in inches */ |
Reniboy | 1:775f6e8071a2 | 71 | void button_isr(); |
Reniboy | 1:775f6e8071a2 | 72 | void init_serial(); //*!< function to activate onboard switches and LEDs */ |
Reniboy | 1:775f6e8071a2 | 73 | void timer_isr(); |
Reniboy | 0:e1ae1b9889a3 | 74 | volatile int g_timer_flag = 0; /** @Brief G flag makes things easier to distinguish as this is a global variable **/ |
Reniboy | 0:e1ae1b9889a3 | 75 | volatile int g_timer2_flag = 0; |
Reniboy | 0:e1ae1b9889a3 | 76 | volatile int g_sw3_flag = 0; |
Reniboy | 1:775f6e8071a2 | 77 | volatile int g_sw2_flag = 0; |
Reniboy | 0:e1ae1b9889a3 | 78 | volatile int g_timer1_flag = 0; |
Reniboy | 0:e1ae1b9889a3 | 79 | void sw2_isr(); |
Reniboy | 0:e1ae1b9889a3 | 80 | void sw3_isr(); |
Reniboy | 0:e1ae1b9889a3 | 81 | |
Reniboy | 1:775f6e8071a2 | 82 | |
Reniboy | 1:775f6e8071a2 | 83 | |
Reniboy | 1:775f6e8071a2 | 84 | |
Reniboy | 1:775f6e8071a2 | 85 | |
Reniboy | 1:775f6e8071a2 | 86 | void delete_file(char filename[]); // Function to call for deletion of file. |
Reniboy | 1:775f6e8071a2 | 87 | |
Reniboy | 0:e1ae1b9889a3 | 88 | /** Misc **/ |
Reniboy | 1:775f6e8071a2 | 89 | |
Reniboy | 0:e1ae1b9889a3 | 90 | float averageDistance(); |
Reniboy | 0:e1ae1b9889a3 | 91 | /** |
Reniboy | 0:e1ae1b9889a3 | 92 | @namespace Average Distance |
Reniboy | 0:e1ae1b9889a3 | 93 | @Brief This function allows us to take ten sensor readings and find the average to improve accuracy |
Reniboy | 0:e1ae1b9889a3 | 94 | **/ |
Reniboy | 0:e1ae1b9889a3 | 95 | float averageDistanceIn(); |
Reniboy | 1:775f6e8071a2 | 96 | /** |
Reniboy | 1:775f6e8071a2 | 97 | @namespace Average Distance in Inches |
Reniboy | 1:775f6e8071a2 | 98 | @Brief Converts the distance from centimetres to inches |
Reniboy | 1:775f6e8071a2 | 99 | **/ |
Reniboy | 0:e1ae1b9889a3 | 100 | |
Reniboy | 0:e1ae1b9889a3 | 101 | int distance; |
Reniboy | 1:775f6e8071a2 | 102 | /** |
Reniboy | 1:775f6e8071a2 | 103 | @namespace Distance |
Reniboy | 1:775f6e8071a2 | 104 | @brief Variable for storing integer value for distance in cm(default) |
Reniboy | 1:775f6e8071a2 | 105 | **/ |
Reniboy | 0:e1ae1b9889a3 | 106 | float distanceIn; |
Reniboy | 1:775f6e8071a2 | 107 | /** |
Reniboy | 1:775f6e8071a2 | 108 | @namespace Distance |
Reniboy | 1:775f6e8071a2 | 109 | @brief Variable for storing integer value for distance in inches |
Reniboy | 1:775f6e8071a2 | 110 | **/ |
Reniboy | 0:e1ae1b9889a3 | 111 | |
Reniboy | 0:e1ae1b9889a3 | 112 | /** Functions **/ |
Reniboy | 0:e1ae1b9889a3 | 113 | |
Reniboy | 0:e1ae1b9889a3 | 114 | void introTune(); |
Reniboy | 0:e1ae1b9889a3 | 115 | /** |
Reniboy | 0:e1ae1b9889a3 | 116 | @namespace Introductory Tune |
Reniboy | 0:e1ae1b9889a3 | 117 | @brief Provides and audible indication that the system is on |
Reniboy | 0:e1ae1b9889a3 | 118 | **/ |
Reniboy | 0:e1ae1b9889a3 | 119 | void beeping(); |
Reniboy | 0:e1ae1b9889a3 | 120 | /** |
Reniboy | 0:e1ae1b9889a3 | 121 | @namespace Beeping function, |
Reniboy | 0:e1ae1b9889a3 | 122 | @brief This function allows the sensor to detect the distance and make the speaker beep accordingly |
Reniboy | 0:e1ae1b9889a3 | 123 | **/ |
Reniboy | 0:e1ae1b9889a3 | 124 | void sensingImage(); |
Reniboy | 0:e1ae1b9889a3 | 125 | /** |
Reniboy | 0:e1ae1b9889a3 | 126 | @Brief This function shows the distance in bars depending on how close an object is |
Reniboy | 0:e1ae1b9889a3 | 127 | **/ |
Reniboy | 0:e1ae1b9889a3 | 128 | void sensingImageIn(); |
Reniboy | 0:e1ae1b9889a3 | 129 | /** |
Reniboy | 0:e1ae1b9889a3 | 130 | @namespace Shows the parking sensor distances in inches |
Reniboy | 0:e1ae1b9889a3 | 131 | @brief Converts the distance into inches |
Reniboy | 0:e1ae1b9889a3 | 132 | **/ |
Reniboy | 0:e1ae1b9889a3 | 133 | void classicMode1(); |
Reniboy | 0:e1ae1b9889a3 | 134 | void radarMode(); |
Reniboy | 0:e1ae1b9889a3 | 135 | /** |
Reniboy | 0:e1ae1b9889a3 | 136 | Function allows the data to be saved on to an SD card including the time and distance |
Reniboy | 0:e1ae1b9889a3 | 137 | **/ |
Reniboy | 0:e1ae1b9889a3 | 138 | void saveData(); |
Reniboy | 0:e1ae1b9889a3 | 139 | /** |
Reniboy | 0:e1ae1b9889a3 | 140 | Function will be concurrent with readings and will be intrinsically tied to the actions of the SD card. |
Reniboy | 0:e1ae1b9889a3 | 141 | **/ |
Reniboy | 0:e1ae1b9889a3 | 142 | void loadData(); /** |
Reniboy | 0:e1ae1b9889a3 | 143 | Creating a function to allow the data to be loaded when and show the records of all the distances and and times |
Reniboy | 0:e1ae1b9889a3 | 144 | **/ |
Reniboy | 0:e1ae1b9889a3 | 145 | void active(); |
Reniboy | 0:e1ae1b9889a3 | 146 | /** |
Reniboy | 1:775f6e8071a2 | 147 | @namespace Active mode in centimetres |
Reniboy | 0:e1ae1b9889a3 | 148 | @Brief Main functionality that essentially reads the distance from the sensor and conveys the information via The display and buzzer |
Reniboy | 0:e1ae1b9889a3 | 149 | **/ |
Reniboy | 1:775f6e8071a2 | 150 | void activeIn(); |
Reniboy | 1:775f6e8071a2 | 151 | /** |
Reniboy | 1:775f6e8071a2 | 152 | @namespace Active Parking Mode in Inches |
Reniboy | 1:775f6e8071a2 | 153 | @brief Function to implement active parking mode in inches with the use of tickers and interrupts to save power |
Reniboy | 1:775f6e8071a2 | 154 | **/ |
Reniboy | 1:775f6e8071a2 | 155 | |
Reniboy | 0:e1ae1b9889a3 | 156 | void radar(); |
Reniboy | 0:e1ae1b9889a3 | 157 | /** |
Reniboy | 0:e1ae1b9889a3 | 158 | @namespace Radar |
Reniboy | 0:e1ae1b9889a3 | 159 | @brief Fucntion calling radar mode so as to allow for use of interrupts |
Reniboy | 0:e1ae1b9889a3 | 160 | **/ |
Reniboy | 0:e1ae1b9889a3 | 161 | void sweepSpeed(); |
Reniboy | 0:e1ae1b9889a3 | 162 | /** @namespace Sweep Speed |
Reniboy | 0:e1ae1b9889a3 | 163 | @Brief Function that varies the rate at which the radar sweeps with the sensor distance |
Reniboy | 0:e1ae1b9889a3 | 164 | **/ |
Reniboy | 1:775f6e8071a2 | 165 | void mainProg(); |
Reniboy | 1:775f6e8071a2 | 166 | |
Reniboy | 1:775f6e8071a2 | 167 | /** |
Reniboy | 1:775f6e8071a2 | 168 | @namespace Main Function |
Reniboy | 1:775f6e8071a2 | 169 | @brief The function containing the main menu to choose functions from |
Reniboy | 1:775f6e8071a2 | 170 | **/ |
Reniboy | 1:775f6e8071a2 | 171 | |
Reniboy | 1:775f6e8071a2 | 172 | void classicMode(); |
Reniboy | 1:775f6e8071a2 | 173 | /** |
Reniboy | 1:775f6e8071a2 | 174 | @namespace Screen selection |
Reniboy | 1:775f6e8071a2 | 175 | @Brief Allow the screen to refresh when the potentiometer is set to reflect output mode due to pot selection |
Reniboy | 1:775f6e8071a2 | 176 | **/ |
Reniboy | 1:775f6e8071a2 | 177 | |
Reniboy | 0:e1ae1b9889a3 | 178 | void sweep(); |
Reniboy | 0:e1ae1b9889a3 | 179 | /**@namespace Sweeping Functions |
Reniboy | 0:e1ae1b9889a3 | 180 | @Brief Each of these functions will read the distance from the sensor and set the radar arrow speed across the screen appropriately |
Reniboy | 0:e1ae1b9889a3 | 181 | **/ |
Reniboy | 0:e1ae1b9889a3 | 182 | void sweepOne(); |
Reniboy | 0:e1ae1b9889a3 | 183 | void sweepTwo(); |
Reniboy | 0:e1ae1b9889a3 | 184 | void sweepThree(); |
Reniboy | 0:e1ae1b9889a3 | 185 | void sweepFour(); |
Reniboy | 0:e1ae1b9889a3 | 186 | void sweepFive(); |
Reniboy | 0:e1ae1b9889a3 | 187 | void sweepSix(); |
Reniboy | 0:e1ae1b9889a3 | 188 | void sweepSeven(); |
Reniboy | 0:e1ae1b9889a3 | 189 | void sweepEight(); |
Reniboy | 0:e1ae1b9889a3 | 190 | void sweepNine(); |
Reniboy | 0:e1ae1b9889a3 | 191 | |
Reniboy | 0:e1ae1b9889a3 | 192 | |
Reniboy | 0:e1ae1b9889a3 | 193 | |
Reniboy | 0:e1ae1b9889a3 | 194 | /** Variables **/ |
Reniboy | 0:e1ae1b9889a3 | 195 | |
Reniboy | 0:e1ae1b9889a3 | 196 | |
Reniboy | 1:775f6e8071a2 | 197 | float i; |
Reniboy | 1:775f6e8071a2 | 198 | /*!< Variables used to control rate at which speaker goes off */ |
Reniboy | 1:775f6e8071a2 | 199 | |
Reniboy | 0:e1ae1b9889a3 | 200 | float t; |
Reniboy | 1:775f6e8071a2 | 201 | /*!< Variable used to vary sweep speed. */ |
Reniboy | 0:e1ae1b9889a3 | 202 | |
Reniboy | 0:e1ae1b9889a3 | 203 | |
Reniboy | 0:e1ae1b9889a3 | 204 |