an ultrasonic sensor used as a car sensor
Dependencies: N5110 PowerControl beep mbed sensor
main.h
00001 /** 00002 @file main.h 00003 @brief Header file containing functions prototypes, defines and global variables. 00004 @brief Revision 1.0. 00005 @author Saleh Jaffal 00006 @date April 2015 00007 */ 00008 00009 #ifndef MAIN_H 00010 #define MAIN_H 00011 //#include "beep.h" 00012 #include "mbed.h" 00013 #include "SRF02.h" 00014 #include "N5110.h" 00015 #include "beep.h" ///@see a library I found to initiate the buzzer 00016 #include "PowerControl/PowerControl.h" 00017 #include "PowerControl/EthernetPowerControl.h" 00018 00019 #define USR_POWERDOWN (0x104) 00020 N5110 lcd(p7,p8,p9,p10,p11,p13,p26); 00021 SRF02 sensor(p28, p27); 00022 /** 00023 @namespace buzzer 00024 @brief output for status buzzer 00025 */ 00026 Beep buzzer(p21); 00027 /** 00028 @namespace green1 00029 @brief GPIO output for status LED 00030 */ 00031 PwmOut green1(p22); 00032 /** 00033 @namespace green2 00034 @brief GPIO output for status LED 00035 */ 00036 PwmOut green2(p23); 00037 /** 00038 @namespace yellow1 00039 @brief GPIO output for status LED 00040 */ 00041 PwmOut yellow1(p24); 00042 /** 00043 @namespace yellow2 00044 @brief GPIO output for status LED 00045 */ 00046 PwmOut yellow2(p25); 00047 /** 00048 @namespace red1 00049 @brief GPIO output for status LED 00050 */ 00051 DigitalOut red1(p29); 00052 /** 00053 @namespace red2 00054 @brief GPIO output for status LED 00055 */ 00056 DigitalOut red2(p30); 00057 /** 00058 @namespace pot 00059 @brief GPIO input for lcd brightness 00060 */ 00061 AnalogIn mypot(p20); 00062 /** 00063 @namespace button 00064 @brief GPIO input to switch values from the sensor 00065 */ 00066 InterruptIn button(p15); 00067 00068 00069 Serial pc(USBTX, USBRX); 00070 00071 00072 00073 void beepOff(); 00074 00075 void beepOn(float t); 00076 00077 /** 00078 Shows the welcome message when the LCD is on 00079 */ 00080 void welcomeMessage(); 00081 /** 00082 gets the distance in cm by dividing 00083 10 read values by 10 00084 @returns the average distance in cm 00085 */ 00086 void getDistanceCm(); 00087 /** 00088 gets the distance in inches by dividing 00089 10 read values by 10 00090 @returns the average distance in inches 00091 */ 00092 void getDistanceIn(); 00093 /** 00094 gets the distance in us by dividing 00095 10 read values by 10 00096 @returns the average distance in us 00097 */ 00098 void getDistanceUs(); 00099 00100 /** 00101 when the button is pressed this 00102 action is called 00103 */ 00104 void buttonPressed(); 00105 /** 00106 looks for where the range of the reading is 00107 to set its conditions 00108 */ 00109 void compDist(); 00110 /** 00111 compares the cases of each distance 00112 to set the Led's values and the buzzer 00113 */ 00114 void distanceA(); 00115 00116 00117 int distanceCm ; /*!< distanceCm set in ISR */ 00118 int distanceIn ; /*!< distanceIn set in ISR */ 00119 int distanceUs ; /*!< distanceUs set in ISR */ 00120 int A ; /*!< used to compare the cases after being set in compDist() */ 00121 00122 /** 00123 All distances used to add 00124 the 10 readings from the sensor 00125 to get an average of 10 readings 00126 per second, so that it will cancel 00127 out the noise. 00128 */ 00129 int distance1; /*!< distance1 set in ISR */ 00130 int distance2 ; /*!< distance2 set in ISR */ 00131 int distance3 ; /*!< distance3 set in ISR */ 00132 int distance4 ; /*!< distance4 set in ISR */ 00133 int distance5 ; /*!< distance5 set in ISR */ 00134 int distance6 ; /*!< distance6 set in ISR */ 00135 int distance7 ; /*!< distance7 set in ISR */ 00136 int distance8 ; /*!< distance8 set in ISR */ 00137 int distance9 ; /*!< distance9 set in ISR */ 00138 int distance10 ; /*!< distance10 set in ISR */ 00139 00140 float mypotVal ; /*!< mypotVal is used to transfer the vlaue of the pot 00141 to lcd brightness */ 00142 int i=0; 00143 int sum ; /*!< used to add all the distances together (ie distance 1, 00144 distance 2, ...*/ 00145 #endif
Generated on Mon Jul 25 2022 18:37:11 by 1.7.2