Reverse Parking sensor
Dependencies: N5110 SRF02 buzzer mbed
Fork of ParkingSENSOR by
main.h@0:e1ae1b9889a3, 2016-05-05 (annotated)
- Committer:
- Reniboy
- Date:
- Thu May 05 00:29:11 2016 +0000
- Revision:
- 0:e1ae1b9889a3
- Child:
- 1:775f6e8071a2
Version 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 | 0:e1ae1b9889a3 | 6 | @date March 2015 **/ |
Reniboy | 0:e1ae1b9889a3 | 7 | |
Reniboy | 0:e1ae1b9889a3 | 8 | |
Reniboy | 0:e1ae1b9889a3 | 9 | #include "mbed.h" |
Reniboy | 0:e1ae1b9889a3 | 10 | #include "N5110.h" |
Reniboy | 0:e1ae1b9889a3 | 11 | #include "SRF02/SRF02.h" |
Reniboy | 0:e1ae1b9889a3 | 12 | #include "buzzer.h" |
Reniboy | 0:e1ae1b9889a3 | 13 | #include "SDFileSystem.h" |
Reniboy | 0:e1ae1b9889a3 | 14 | |
Reniboy | 0:e1ae1b9889a3 | 15 | /** INPUTS AND OUTPUTS **/ |
Reniboy | 0:e1ae1b9889a3 | 16 | |
Reniboy | 0:e1ae1b9889a3 | 17 | N5110 lcd (PTE26, PTA0, PTC4, PTD0, PTD2, PTD1, PTC3); |
Reniboy | 0:e1ae1b9889a3 | 18 | /** @brief Connections for the LCD Display **/ |
Reniboy | 0:e1ae1b9889a3 | 19 | SRF02 sensor(I2C_SDA,I2C_SCL); |
Reniboy | 0:e1ae1b9889a3 | 20 | /** @brief Ultrasonic distance sensor connected in I2C mode**/ |
Reniboy | 0:e1ae1b9889a3 | 21 | Beep buzzer(PTA2); |
Reniboy | 0:e1ae1b9889a3 | 22 | /** |
Reniboy | 0:e1ae1b9889a3 | 23 | @brief Piezo type buzzer that can produce notes and vary the frequency as well. Connected to Pwm signal |
Reniboy | 0:e1ae1b9889a3 | 24 | **/ |
Reniboy | 0:e1ae1b9889a3 | 25 | |
Reniboy | 0:e1ae1b9889a3 | 26 | InterruptIn button(PTB18); |
Reniboy | 0:e1ae1b9889a3 | 27 | /** |
Reniboy | 0:e1ae1b9889a3 | 28 | @Brief Button connected to mbed with the use of InterruptIn class**/ |
Reniboy | 0:e1ae1b9889a3 | 29 | InterruptIn sw2(SW2); |
Reniboy | 0:e1ae1b9889a3 | 30 | |
Reniboy | 0:e1ae1b9889a3 | 31 | |
Reniboy | 0:e1ae1b9889a3 | 32 | InterruptIn sw3(SW3); |
Reniboy | 0:e1ae1b9889a3 | 33 | DigitalOut r_led(PTC2); |
Reniboy | 0:e1ae1b9889a3 | 34 | |
Reniboy | 0:e1ae1b9889a3 | 35 | SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); |
Reniboy | 0:e1ae1b9889a3 | 36 | /** Defining pins for SD card file system **/ |
Reniboy | 0:e1ae1b9889a3 | 37 | Serial serial(USBTX, USBRX); // for PC debugging purposes |
Reniboy | 0:e1ae1b9889a3 | 38 | AnalogIn pot(PTB2); /* Potentiometer middle pin connected to PTB3, other two ends connected to GND and 3.3V */ |
Reniboy | 0:e1ae1b9889a3 | 39 | |
Reniboy | 0:e1ae1b9889a3 | 40 | |
Reniboy | 0:e1ae1b9889a3 | 41 | |
Reniboy | 0:e1ae1b9889a3 | 42 | /** Create objects for timeout using flipper **/ |
Reniboy | 0:e1ae1b9889a3 | 43 | Timeout flipper; |
Reniboy | 0:e1ae1b9889a3 | 44 | Timeout flipper2; |
Reniboy | 0:e1ae1b9889a3 | 45 | Ticker ticker; |
Reniboy | 0:e1ae1b9889a3 | 46 | Ticker ticker2; |
Reniboy | 0:e1ae1b9889a3 | 47 | Ticker ticker3; |
Reniboy | 0:e1ae1b9889a3 | 48 | void button_isr(); |
Reniboy | 0:e1ae1b9889a3 | 49 | void init_serial(); /** function to activate onboard switches and LEDs **/ |
Reniboy | 0:e1ae1b9889a3 | 50 | void timer_isr(); |
Reniboy | 0:e1ae1b9889a3 | 51 | void timer2_isr(); |
Reniboy | 0:e1ae1b9889a3 | 52 | void timer1_isr(); |
Reniboy | 0:e1ae1b9889a3 | 53 | void mainProg(); |
Reniboy | 0:e1ae1b9889a3 | 54 | void inActiveState(); |
Reniboy | 0:e1ae1b9889a3 | 55 | /** |
Reniboy | 0:e1ae1b9889a3 | 56 | @namespace Main Function |
Reniboy | 0:e1ae1b9889a3 | 57 | @brief The function containing the main menu to choose functions from |
Reniboy | 0:e1ae1b9889a3 | 58 | **/ |
Reniboy | 0:e1ae1b9889a3 | 59 | |
Reniboy | 0:e1ae1b9889a3 | 60 | void classicMode(); /** |
Reniboy | 0:e1ae1b9889a3 | 61 | @Brief Allow the screen to refresh when the potentiometer is set to reflect output mode. |
Reniboy | 0:e1ae1b9889a3 | 62 | **/ |
Reniboy | 0:e1ae1b9889a3 | 63 | |
Reniboy | 0:e1ae1b9889a3 | 64 | void delete_file(char filename[]); // Function to call for deletion of file. |
Reniboy | 0:e1ae1b9889a3 | 65 | |
Reniboy | 0:e1ae1b9889a3 | 66 | /** Flags and Interrupt Service Routines **/ |
Reniboy | 0:e1ae1b9889a3 | 67 | |
Reniboy | 0:e1ae1b9889a3 | 68 | volatile int g_timer_flag = 0; /** @Brief G flag makes things easier to distinguish as this is a global variable **/ |
Reniboy | 0:e1ae1b9889a3 | 69 | volatile int g_timer2_flag = 0; |
Reniboy | 0:e1ae1b9889a3 | 70 | volatile int g_sw3_flag = 0; |
Reniboy | 0:e1ae1b9889a3 | 71 | volatile int g_button_flag = 0; |
Reniboy | 0:e1ae1b9889a3 | 72 | volatile int g_timer1_flag = 0; |
Reniboy | 0:e1ae1b9889a3 | 73 | void sw2_isr(); |
Reniboy | 0:e1ae1b9889a3 | 74 | void sw3_isr(); |
Reniboy | 0:e1ae1b9889a3 | 75 | |
Reniboy | 0:e1ae1b9889a3 | 76 | /** Misc **/ |
Reniboy | 0:e1ae1b9889a3 | 77 | float averageDistance(); |
Reniboy | 0:e1ae1b9889a3 | 78 | /** |
Reniboy | 0:e1ae1b9889a3 | 79 | @namespace Average Distance |
Reniboy | 0:e1ae1b9889a3 | 80 | @Brief This function allows us to take ten sensor readings and find the average to improve accuracy |
Reniboy | 0:e1ae1b9889a3 | 81 | **/ |
Reniboy | 0:e1ae1b9889a3 | 82 | float averageDistanceIn(); |
Reniboy | 0:e1ae1b9889a3 | 83 | |
Reniboy | 0:e1ae1b9889a3 | 84 | int distance; |
Reniboy | 0:e1ae1b9889a3 | 85 | float distanceIn; |
Reniboy | 0:e1ae1b9889a3 | 86 | |
Reniboy | 0:e1ae1b9889a3 | 87 | |
Reniboy | 0:e1ae1b9889a3 | 88 | /** Functions **/ |
Reniboy | 0:e1ae1b9889a3 | 89 | |
Reniboy | 0:e1ae1b9889a3 | 90 | void introTune(); |
Reniboy | 0:e1ae1b9889a3 | 91 | /** |
Reniboy | 0:e1ae1b9889a3 | 92 | @namespace Introductory Tune |
Reniboy | 0:e1ae1b9889a3 | 93 | @brief Provides and audible indication that the system is on |
Reniboy | 0:e1ae1b9889a3 | 94 | **/ |
Reniboy | 0:e1ae1b9889a3 | 95 | void beeping(); |
Reniboy | 0:e1ae1b9889a3 | 96 | /** |
Reniboy | 0:e1ae1b9889a3 | 97 | @namespace Beeping function, |
Reniboy | 0:e1ae1b9889a3 | 98 | @brief This function allows the sensor to detect the distance and make the speaker beep accordingly |
Reniboy | 0:e1ae1b9889a3 | 99 | **/ |
Reniboy | 0:e1ae1b9889a3 | 100 | void sensingImage(); |
Reniboy | 0:e1ae1b9889a3 | 101 | /** |
Reniboy | 0:e1ae1b9889a3 | 102 | @Brief This function shows the distance in bars depending on how close an object is |
Reniboy | 0:e1ae1b9889a3 | 103 | **/ |
Reniboy | 0:e1ae1b9889a3 | 104 | void sensingImageIn(); |
Reniboy | 0:e1ae1b9889a3 | 105 | /** |
Reniboy | 0:e1ae1b9889a3 | 106 | @namespace Shows the parking sensor distances in inches |
Reniboy | 0:e1ae1b9889a3 | 107 | @brief Converts the distance into inches |
Reniboy | 0:e1ae1b9889a3 | 108 | **/ |
Reniboy | 0:e1ae1b9889a3 | 109 | void classicMode1(); |
Reniboy | 0:e1ae1b9889a3 | 110 | void radarMode(); |
Reniboy | 0:e1ae1b9889a3 | 111 | /** |
Reniboy | 0:e1ae1b9889a3 | 112 | Function allows the data to be saved on to an SD card including the time and distance |
Reniboy | 0:e1ae1b9889a3 | 113 | **/ |
Reniboy | 0:e1ae1b9889a3 | 114 | void saveData(); |
Reniboy | 0:e1ae1b9889a3 | 115 | /** |
Reniboy | 0:e1ae1b9889a3 | 116 | Function will be concurrent with readings and will be intrinsically tied to the actions of the SD card. |
Reniboy | 0:e1ae1b9889a3 | 117 | **/ |
Reniboy | 0:e1ae1b9889a3 | 118 | void loadData(); /** |
Reniboy | 0:e1ae1b9889a3 | 119 | 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 | 120 | **/ |
Reniboy | 0:e1ae1b9889a3 | 121 | void active(); |
Reniboy | 0:e1ae1b9889a3 | 122 | /** |
Reniboy | 0:e1ae1b9889a3 | 123 | @Brief Main functionality that essentially reads the distance from the sensor and conveys the information via The display and buzzer |
Reniboy | 0:e1ae1b9889a3 | 124 | **/ |
Reniboy | 0:e1ae1b9889a3 | 125 | void radar(); |
Reniboy | 0:e1ae1b9889a3 | 126 | /** |
Reniboy | 0:e1ae1b9889a3 | 127 | @namespace Radar |
Reniboy | 0:e1ae1b9889a3 | 128 | @brief Fucntion calling radar mode so as to allow for use of interrupts |
Reniboy | 0:e1ae1b9889a3 | 129 | **/ |
Reniboy | 0:e1ae1b9889a3 | 130 | void sweepSpeed(); |
Reniboy | 0:e1ae1b9889a3 | 131 | /** @namespace Sweep Speed |
Reniboy | 0:e1ae1b9889a3 | 132 | @Brief Function that varies the rate at which the radar sweeps with the sensor distance |
Reniboy | 0:e1ae1b9889a3 | 133 | **/ |
Reniboy | 0:e1ae1b9889a3 | 134 | void sweep(); |
Reniboy | 0:e1ae1b9889a3 | 135 | /**@namespace Sweeping Functions |
Reniboy | 0:e1ae1b9889a3 | 136 | @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 | 137 | **/ |
Reniboy | 0:e1ae1b9889a3 | 138 | void sweepOne(); |
Reniboy | 0:e1ae1b9889a3 | 139 | void sweepTwo(); |
Reniboy | 0:e1ae1b9889a3 | 140 | void sweepThree(); |
Reniboy | 0:e1ae1b9889a3 | 141 | void sweepFour(); |
Reniboy | 0:e1ae1b9889a3 | 142 | void sweepFive(); |
Reniboy | 0:e1ae1b9889a3 | 143 | void sweepSix(); |
Reniboy | 0:e1ae1b9889a3 | 144 | void sweepSeven(); |
Reniboy | 0:e1ae1b9889a3 | 145 | void sweepEight(); |
Reniboy | 0:e1ae1b9889a3 | 146 | void sweepNine(); |
Reniboy | 0:e1ae1b9889a3 | 147 | |
Reniboy | 0:e1ae1b9889a3 | 148 | |
Reniboy | 0:e1ae1b9889a3 | 149 | |
Reniboy | 0:e1ae1b9889a3 | 150 | /** Variables **/ |
Reniboy | 0:e1ae1b9889a3 | 151 | |
Reniboy | 0:e1ae1b9889a3 | 152 | |
Reniboy | 0:e1ae1b9889a3 | 153 | float i; /** |
Reniboy | 0:e1ae1b9889a3 | 154 | @brief Variable used to vary frequency of the buzzer |
Reniboy | 0:e1ae1b9889a3 | 155 | **/ |
Reniboy | 0:e1ae1b9889a3 | 156 | float t; |
Reniboy | 0:e1ae1b9889a3 | 157 | /** |
Reniboy | 0:e1ae1b9889a3 | 158 | @brief Variable used to vary frequency of the radar sweep |
Reniboy | 0:e1ae1b9889a3 | 159 | **/ |
Reniboy | 0:e1ae1b9889a3 | 160 | |
Reniboy | 0:e1ae1b9889a3 | 161 | |
Reniboy | 0:e1ae1b9889a3 | 162 | |
Reniboy | 0:e1ae1b9889a3 | 163 | |
Reniboy | 0:e1ae1b9889a3 | 164 | |
Reniboy | 0:e1ae1b9889a3 | 165 |