![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
My ELEC2645 sensor project Bader Alathri 200826344
Dependencies: FXOS8700Q N5110 SRF02 mbed
main.h@0:fedc789ee1f0, 2016-05-05 (annotated)
- Committer:
- fy13ba
- Date:
- Thu May 05 14:59:50 2016 +0000
- Revision:
- 0:fedc789ee1f0
final version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fy13ba | 0:fedc789ee1f0 | 1 | /** |
fy13ba | 0:fedc789ee1f0 | 2 | @file main.h |
fy13ba | 0:fedc789ee1f0 | 3 | @brief Header file containing functions prototypes, defines and global variables. |
fy13ba | 0:fedc789ee1f0 | 4 | @brief Leeds University ELEC2645 sensor project |
fy13ba | 0:fedc789ee1f0 | 5 | @author Bader Alathri |
fy13ba | 0:fedc789ee1f0 | 6 | @date May 2016 |
fy13ba | 0:fedc789ee1f0 | 7 | */ |
fy13ba | 0:fedc789ee1f0 | 8 | |
fy13ba | 0:fedc789ee1f0 | 9 | #ifndef MAIN_H |
fy13ba | 0:fedc789ee1f0 | 10 | #define MAIN_H |
fy13ba | 0:fedc789ee1f0 | 11 | |
fy13ba | 0:fedc789ee1f0 | 12 | |
fy13ba | 0:fedc789ee1f0 | 13 | #include "mbed.h" |
fy13ba | 0:fedc789ee1f0 | 14 | #include "N5110.h" |
fy13ba | 0:fedc789ee1f0 | 15 | #include "SRF02.h" |
fy13ba | 0:fedc789ee1f0 | 16 | #include "FXOS8700Q.h" /** |
fy13ba | 0:fedc789ee1f0 | 17 | @see https://developer.mbed.org/teams/Freescale/code/Hello_FXOS8700Q/ |
fy13ba | 0:fedc789ee1f0 | 18 | */ |
fy13ba | 0:fedc789ee1f0 | 19 | |
fy13ba | 0:fedc789ee1f0 | 20 | |
fy13ba | 0:fedc789ee1f0 | 21 | |
fy13ba | 0:fedc789ee1f0 | 22 | /** |
fy13ba | 0:fedc789ee1f0 | 23 | @namespace lcd |
fy13ba | 0:fedc789ee1f0 | 24 | @brief output pins for N5110 LCD |
fy13ba | 0:fedc789ee1f0 | 25 | @brief (PWR,SCE,RST,D/C,MOSI,SCLK,LED)**** |
fy13ba | 0:fedc789ee1f0 | 26 | */ |
fy13ba | 0:fedc789ee1f0 | 27 | N5110 lcd(PTA1,PTA0,PTC4,PTD0,PTD2,PTD1,PTC3); |
fy13ba | 0:fedc789ee1f0 | 28 | |
fy13ba | 0:fedc789ee1f0 | 29 | |
fy13ba | 0:fedc789ee1f0 | 30 | /** |
fy13ba | 0:fedc789ee1f0 | 31 | @namespace sensor |
fy13ba | 0:fedc789ee1f0 | 32 | @brief output pins for SRF02 sensor |
fy13ba | 0:fedc789ee1f0 | 33 | */ |
fy13ba | 0:fedc789ee1f0 | 34 | SRF02 sensor(PTE25,PTE24); |
fy13ba | 0:fedc789ee1f0 | 35 | |
fy13ba | 0:fedc789ee1f0 | 36 | /** |
fy13ba | 0:fedc789ee1f0 | 37 | @namespace acc |
fy13ba | 0:fedc789ee1f0 | 38 | @brief output pins for FXOS8700 |
fy13ba | 0:fedc789ee1f0 | 39 | @brief onboard accelerometer |
fy13ba | 0:fedc789ee1f0 | 40 | */ |
fy13ba | 0:fedc789ee1f0 | 41 | FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); |
fy13ba | 0:fedc789ee1f0 | 42 | |
fy13ba | 0:fedc789ee1f0 | 43 | /** |
fy13ba | 0:fedc789ee1f0 | 44 | @namespace pc |
fy13ba | 0:fedc789ee1f0 | 45 | @brief UART connection for PC |
fy13ba | 0:fedc789ee1f0 | 46 | */ |
fy13ba | 0:fedc789ee1f0 | 47 | Serial pc(USBTX,USBRX); |
fy13ba | 0:fedc789ee1f0 | 48 | |
fy13ba | 0:fedc789ee1f0 | 49 | /** |
fy13ba | 0:fedc789ee1f0 | 50 | @see https://developer.mbed.org/teams/Freescale/code/Hello_FXOS8700Q/ |
fy13ba | 0:fedc789ee1f0 | 51 | @brief retrieves data from accelerometer |
fy13ba | 0:fedc789ee1f0 | 52 | @brief taken from FXOS8700Q library |
fy13ba | 0:fedc789ee1f0 | 53 | */ |
fy13ba | 0:fedc789ee1f0 | 54 | MotionSensorDataUnits acc_data; |
fy13ba | 0:fedc789ee1f0 | 55 | |
fy13ba | 0:fedc789ee1f0 | 56 | |
fy13ba | 0:fedc789ee1f0 | 57 | /** |
fy13ba | 0:fedc789ee1f0 | 58 | @namespace r_led |
fy13ba | 0:fedc789ee1f0 | 59 | @brief GPIO output for external red LED |
fy13ba | 0:fedc789ee1f0 | 60 | */ |
fy13ba | 0:fedc789ee1f0 | 61 | DigitalOut r_led(PTC8); |
fy13ba | 0:fedc789ee1f0 | 62 | |
fy13ba | 0:fedc789ee1f0 | 63 | /** |
fy13ba | 0:fedc789ee1f0 | 64 | @namespace g_led |
fy13ba | 0:fedc789ee1f0 | 65 | @brief GPIO output for external green LED |
fy13ba | 0:fedc789ee1f0 | 66 | */ |
fy13ba | 0:fedc789ee1f0 | 67 | DigitalOut g_led(PTC1); |
fy13ba | 0:fedc789ee1f0 | 68 | |
fy13ba | 0:fedc789ee1f0 | 69 | /** |
fy13ba | 0:fedc789ee1f0 | 70 | @namespace red_led |
fy13ba | 0:fedc789ee1f0 | 71 | @brief output for onboard red LED |
fy13ba | 0:fedc789ee1f0 | 72 | */ |
fy13ba | 0:fedc789ee1f0 | 73 | DigitalOut red_led(LED_RED); |
fy13ba | 0:fedc789ee1f0 | 74 | |
fy13ba | 0:fedc789ee1f0 | 75 | /** |
fy13ba | 0:fedc789ee1f0 | 76 | @namespace green_led |
fy13ba | 0:fedc789ee1f0 | 77 | @brief output for onboard green LED |
fy13ba | 0:fedc789ee1f0 | 78 | */ |
fy13ba | 0:fedc789ee1f0 | 79 | DigitalOut green_led(LED_GREEN); |
fy13ba | 0:fedc789ee1f0 | 80 | |
fy13ba | 0:fedc789ee1f0 | 81 | /** |
fy13ba | 0:fedc789ee1f0 | 82 | @namespace blue_led |
fy13ba | 0:fedc789ee1f0 | 83 | @brief output for onboard blue LED |
fy13ba | 0:fedc789ee1f0 | 84 | */ |
fy13ba | 0:fedc789ee1f0 | 85 | DigitalOut blue_led(LED_BLUE); |
fy13ba | 0:fedc789ee1f0 | 86 | |
fy13ba | 0:fedc789ee1f0 | 87 | /** |
fy13ba | 0:fedc789ee1f0 | 88 | @namespace toggle |
fy13ba | 0:fedc789ee1f0 | 89 | @brief GPIO interrupt input for external toggle button |
fy13ba | 0:fedc789ee1f0 | 90 | */ |
fy13ba | 0:fedc789ee1f0 | 91 | InterruptIn toggle(PTC5); |
fy13ba | 0:fedc789ee1f0 | 92 | |
fy13ba | 0:fedc789ee1f0 | 93 | /** |
fy13ba | 0:fedc789ee1f0 | 94 | @namespace select |
fy13ba | 0:fedc789ee1f0 | 95 | @brief GPIO interrupt input for external select button |
fy13ba | 0:fedc789ee1f0 | 96 | */ |
fy13ba | 0:fedc789ee1f0 | 97 | InterruptIn select(PTC7); |
fy13ba | 0:fedc789ee1f0 | 98 | |
fy13ba | 0:fedc789ee1f0 | 99 | /** |
fy13ba | 0:fedc789ee1f0 | 100 | @namespace ticker1 |
fy13ba | 0:fedc789ee1f0 | 101 | @brief periodically calls timer1_isr |
fy13ba | 0:fedc789ee1f0 | 102 | */ |
fy13ba | 0:fedc789ee1f0 | 103 | Ticker ticker1; |
fy13ba | 0:fedc789ee1f0 | 104 | |
fy13ba | 0:fedc789ee1f0 | 105 | |
fy13ba | 0:fedc789ee1f0 | 106 | volatile int g_select_flag = 0; /*!< flag to be set in ISR when select button is pressed*/ |
fy13ba | 0:fedc789ee1f0 | 107 | volatile int g_toggle_flag = 0; /*!< flag to be set in ISR when toggle button is pressed*/ |
fy13ba | 0:fedc789ee1f0 | 108 | volatile int g_timer1_flag =0; /*!< flag to be set in ISR when periodically by ticker1 is pressed*/ |
fy13ba | 0:fedc789ee1f0 | 109 | volatile int g_error_flag = 0; /*!< flag to be set when measurement error is detected*/ |
fy13ba | 0:fedc789ee1f0 | 110 | |
fy13ba | 0:fedc789ee1f0 | 111 | float total_distance; /*!< stores the sum of the 10 SRF02 readings */ |
fy13ba | 0:fedc789ee1f0 | 112 | float average_distance_cm; /*!< stores the average distance calculated in cm*/ |
fy13ba | 0:fedc789ee1f0 | 113 | float average_distance_in; /*!< stores the average distance calculated in inches */ |
fy13ba | 0:fedc789ee1f0 | 114 | float average_z; /*!< stores the calculated average z-axis value */ |
fy13ba | 0:fedc789ee1f0 | 115 | float brightness; /*!< stores the brightness value*/ |
fy13ba | 0:fedc789ee1f0 | 116 | |
fy13ba | 0:fedc789ee1f0 | 117 | |
fy13ba | 0:fedc789ee1f0 | 118 | /** |
fy13ba | 0:fedc789ee1f0 | 119 | Interrupt service routine for select button |
fy13ba | 0:fedc789ee1f0 | 120 | sets select button flag |
fy13ba | 0:fedc789ee1f0 | 121 | */ |
fy13ba | 0:fedc789ee1f0 | 122 | void select_isr(); |
fy13ba | 0:fedc789ee1f0 | 123 | |
fy13ba | 0:fedc789ee1f0 | 124 | /** |
fy13ba | 0:fedc789ee1f0 | 125 | Interrupt service routine for toggle button |
fy13ba | 0:fedc789ee1f0 | 126 | sets toggle button flag |
fy13ba | 0:fedc789ee1f0 | 127 | */ |
fy13ba | 0:fedc789ee1f0 | 128 | void toggle_isr(); |
fy13ba | 0:fedc789ee1f0 | 129 | |
fy13ba | 0:fedc789ee1f0 | 130 | /** |
fy13ba | 0:fedc789ee1f0 | 131 | Interrupt service routine for ticker1 |
fy13ba | 0:fedc789ee1f0 | 132 | sets timer1 flag |
fy13ba | 0:fedc789ee1f0 | 133 | */ |
fy13ba | 0:fedc789ee1f0 | 134 | void timer1_isr(); |
fy13ba | 0:fedc789ee1f0 | 135 | |
fy13ba | 0:fedc789ee1f0 | 136 | /** |
fy13ba | 0:fedc789ee1f0 | 137 | lights up external red LED and displays error message on LCD |
fy13ba | 0:fedc789ee1f0 | 138 | */ |
fy13ba | 0:fedc789ee1f0 | 139 | void measurement_error(); |
fy13ba | 0:fedc789ee1f0 | 140 | |
fy13ba | 0:fedc789ee1f0 | 141 | /** |
fy13ba | 0:fedc789ee1f0 | 142 | displays measurement transition screen and turns off external LEDs |
fy13ba | 0:fedc789ee1f0 | 143 | */ |
fy13ba | 0:fedc789ee1f0 | 144 | void measuring_transition(); |
fy13ba | 0:fedc789ee1f0 | 145 | |
fy13ba | 0:fedc789ee1f0 | 146 | /** |
fy13ba | 0:fedc789ee1f0 | 147 | calculates average distance in cm from 10 SRF02 readings |
fy13ba | 0:fedc789ee1f0 | 148 | and saves it in average_distance_cm variable; |
fy13ba | 0:fedc789ee1f0 | 149 | */ |
fy13ba | 0:fedc789ee1f0 | 150 | void get_average_distance_cm(); |
fy13ba | 0:fedc789ee1f0 | 151 | |
fy13ba | 0:fedc789ee1f0 | 152 | /** |
fy13ba | 0:fedc789ee1f0 | 153 | calculates average distance in inches from 10 SRF02 readings |
fy13ba | 0:fedc789ee1f0 | 154 | and saves it in average_distance_in variable; |
fy13ba | 0:fedc789ee1f0 | 155 | */ |
fy13ba | 0:fedc789ee1f0 | 156 | void get_average_distance_in(); |
fy13ba | 0:fedc789ee1f0 | 157 | |
fy13ba | 0:fedc789ee1f0 | 158 | /** |
fy13ba | 0:fedc789ee1f0 | 159 | displays calculated average distance in cm on lcd |
fy13ba | 0:fedc789ee1f0 | 160 | including the units |
fy13ba | 0:fedc789ee1f0 | 161 | */ |
fy13ba | 0:fedc789ee1f0 | 162 | void display_distance_cm(); |
fy13ba | 0:fedc789ee1f0 | 163 | |
fy13ba | 0:fedc789ee1f0 | 164 | /** |
fy13ba | 0:fedc789ee1f0 | 165 | displays calculated average distance in inches on lcd |
fy13ba | 0:fedc789ee1f0 | 166 | including the units |
fy13ba | 0:fedc789ee1f0 | 167 | */ |
fy13ba | 0:fedc789ee1f0 | 168 | void display_distance_in(); |
fy13ba | 0:fedc789ee1f0 | 169 | |
fy13ba | 0:fedc789ee1f0 | 170 | /** |
fy13ba | 0:fedc789ee1f0 | 171 | gets average z-axis value from 10 readings in 0.1 seconds |
fy13ba | 0:fedc789ee1f0 | 172 | of the onboard FXOS8700 accelerometer |
fy13ba | 0:fedc789ee1f0 | 173 | and saves it in the average_z variable |
fy13ba | 0:fedc789ee1f0 | 174 | */ |
fy13ba | 0:fedc789ee1f0 | 175 | void get_z_axis_value(); |
fy13ba | 0:fedc789ee1f0 | 176 | |
fy13ba | 0:fedc789ee1f0 | 177 | /** |
fy13ba | 0:fedc789ee1f0 | 178 | according to the calculated average_z value, |
fy13ba | 0:fedc789ee1f0 | 179 | displays on lcd whether surface is flat or not |
fy13ba | 0:fedc789ee1f0 | 180 | specifying whether it is flat horizontally or vertically |
fy13ba | 0:fedc789ee1f0 | 181 | */ |
fy13ba | 0:fedc789ee1f0 | 182 | void display_flatness(); |
fy13ba | 0:fedc789ee1f0 | 183 | |
fy13ba | 0:fedc789ee1f0 | 184 | /** |
fy13ba | 0:fedc789ee1f0 | 185 | increases brightness value by 0.2 if it is less than 1.0, |
fy13ba | 0:fedc789ee1f0 | 186 | and changes brightness to 0 if it is already at 1.0 |
fy13ba | 0:fedc789ee1f0 | 187 | */ |
fy13ba | 0:fedc789ee1f0 | 188 | void adjust_brightness(); |
fy13ba | 0:fedc789ee1f0 | 189 | |
fy13ba | 0:fedc789ee1f0 | 190 | /** |
fy13ba | 0:fedc789ee1f0 | 191 | displays brightness as a percentage on lcd |
fy13ba | 0:fedc789ee1f0 | 192 | */ |
fy13ba | 0:fedc789ee1f0 | 193 | void display_brightness(); |
fy13ba | 0:fedc789ee1f0 | 194 | |
fy13ba | 0:fedc789ee1f0 | 195 | /** |
fy13ba | 0:fedc789ee1f0 | 196 | error function hangs flashing onboard LED |
fy13ba | 0:fedc789ee1f0 | 197 | */ |
fy13ba | 0:fedc789ee1f0 | 198 | void error(); |
fy13ba | 0:fedc789ee1f0 | 199 | |
fy13ba | 0:fedc789ee1f0 | 200 | /** |
fy13ba | 0:fedc789ee1f0 | 201 | setup serial port |
fy13ba | 0:fedc789ee1f0 | 202 | */ |
fy13ba | 0:fedc789ee1f0 | 203 | void init_serial(); |
fy13ba | 0:fedc789ee1f0 | 204 | |
fy13ba | 0:fedc789ee1f0 | 205 | /** |
fy13ba | 0:fedc789ee1f0 | 206 | set-up the on-board LEDs |
fy13ba | 0:fedc789ee1f0 | 207 | */ |
fy13ba | 0:fedc789ee1f0 | 208 | void init_K64F(); |
fy13ba | 0:fedc789ee1f0 | 209 | |
fy13ba | 0:fedc789ee1f0 | 210 | |
fy13ba | 0:fedc789ee1f0 | 211 | |
fy13ba | 0:fedc789ee1f0 | 212 | |
fy13ba | 0:fedc789ee1f0 | 213 | #endif |