Reverse Parking sensor
Dependencies: N5110 SRF02 buzzer mbed
Fork of ParkingSENSOR by
main.cpp@3:68cabac00547, 2016-05-05 (annotated)
- Committer:
- Reniboy
- Date:
- Thu May 05 14:29:39 2016 +0000
- Revision:
- 3:68cabac00547
- Parent:
- 2:31c5c3b46742
Parking sensor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Reniboy | 0:e1ae1b9889a3 | 1 | /** |
Reniboy | 0:e1ae1b9889a3 | 2 | @Brief Program implementation |
Reniboy | 0:e1ae1b9889a3 | 3 | @file main.cpp |
Reniboy | 1:775f6e8071a2 | 4 | @Author Renosi Momoh |
Reniboy | 1:775f6e8071a2 | 5 | @Date 1st May 2016 |
Reniboy | 0:e1ae1b9889a3 | 6 | **/ |
Reniboy | 0:e1ae1b9889a3 | 7 | |
Reniboy | 0:e1ae1b9889a3 | 8 | |
Reniboy | 0:e1ae1b9889a3 | 9 | #include "main.h" |
Reniboy | 0:e1ae1b9889a3 | 10 | |
Reniboy | 0:e1ae1b9889a3 | 11 | int main() |
Reniboy | 0:e1ae1b9889a3 | 12 | { |
Reniboy | 0:e1ae1b9889a3 | 13 | lcd.init(); |
Reniboy | 1:775f6e8071a2 | 14 | lcd.setBrightness(0.6); //set backlight |
Reniboy | 0:e1ae1b9889a3 | 15 | lcd.printString("Renosi Momoh's",0,1); /** Setting the Introduction text to the screen when the mbed is turned on **/ |
Reniboy | 0:e1ae1b9889a3 | 16 | lcd.printString("Parking Sensor",0,2); |
Reniboy | 0:e1ae1b9889a3 | 17 | lcd.printString("Project",16,3); |
Reniboy | 0:e1ae1b9889a3 | 18 | lcd.printString("LEEDS UNIV.",0,5); |
Reniboy | 0:e1ae1b9889a3 | 19 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 20 | introTune(); |
Reniboy | 0:e1ae1b9889a3 | 21 | wait(3); |
Reniboy | 0:e1ae1b9889a3 | 22 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 23 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 24 | r_led = 1; |
Reniboy | 2:31c5c3b46742 | 25 | sw2.mode(PullNone); // Set pullup button |
Reniboy | 1:775f6e8071a2 | 26 | sw2.fall(&sw2_isr); |
Reniboy | 0:e1ae1b9889a3 | 27 | sw3.mode(PullNone); |
Reniboy | 0:e1ae1b9889a3 | 28 | sw3.fall(&sw3_isr); |
Reniboy | 0:e1ae1b9889a3 | 29 | mainProg(); |
Reniboy | 1:775f6e8071a2 | 30 | |
Reniboy | 0:e1ae1b9889a3 | 31 | } |
Reniboy | 0:e1ae1b9889a3 | 32 | |
Reniboy | 0:e1ae1b9889a3 | 33 | |
Reniboy | 0:e1ae1b9889a3 | 34 | void mainProg() |
Reniboy | 0:e1ae1b9889a3 | 35 | { |
Reniboy | 2:31c5c3b46742 | 36 | sw2.mode(PullNone); |
Reniboy | 2:31c5c3b46742 | 37 | sw2.fall(&sw2_isr); |
Reniboy | 1:775f6e8071a2 | 38 | |
Reniboy | 0:e1ae1b9889a3 | 39 | |
Reniboy | 0:e1ae1b9889a3 | 40 | while(1) { |
Reniboy | 1:775f6e8071a2 | 41 | float ain = pot.read(); //set the potentiometer to return values between 0 and 1 |
Reniboy | 0:e1ae1b9889a3 | 42 | ain = pot.read(); |
Reniboy | 0:e1ae1b9889a3 | 43 | if (ain < 0.3 ) { |
Reniboy | 0:e1ae1b9889a3 | 44 | classicMode(); //refresh the lcd display to show classic mode selection as the pot is changed |
Reniboy | 1:775f6e8071a2 | 45 | if (g_sw2_flag) { |
Reniboy | 1:775f6e8071a2 | 46 | g_sw2_flag = 0; //clear the flag |
Reniboy | 1:775f6e8071a2 | 47 | buzzer.beep(1700,0.2);//make sound when sw2 is pressed |
Reniboy | 2:31c5c3b46742 | 48 | active(); |
Reniboy | 1:775f6e8071a2 | 49 | beeping();//This function is called to vary the speaker with the distance for each subsequent function |
Reniboy | 1:775f6e8071a2 | 50 | } |
Reniboy | 2:31c5c3b46742 | 51 | |
Reniboy | 0:e1ae1b9889a3 | 52 | } |
Reniboy | 0:e1ae1b9889a3 | 53 | |
Reniboy | 1:775f6e8071a2 | 54 | if (ain < 0.7 && ain > 0.3) { |
Reniboy | 1:775f6e8071a2 | 55 | radarMode(); //show lcd selection of radar mode when pot value is changed. |
Reniboy | 1:775f6e8071a2 | 56 | if (g_sw2_flag) { |
Reniboy | 1:775f6e8071a2 | 57 | g_sw2_flag = 0; //clear the flag |
Reniboy | 1:775f6e8071a2 | 58 | buzzer.beep(1700,0.2); //make sound when selection is chosen |
Reniboy | 0:e1ae1b9889a3 | 59 | radar(); |
Reniboy | 0:e1ae1b9889a3 | 60 | beeping(); |
Reniboy | 1:775f6e8071a2 | 61 | |
Reniboy | 0:e1ae1b9889a3 | 62 | } |
Reniboy | 2:31c5c3b46742 | 63 | |
Reniboy | 1:775f6e8071a2 | 64 | } |
Reniboy | 1:775f6e8071a2 | 65 | if (ain > 0.7) { |
Reniboy | 1:775f6e8071a2 | 66 | classicMode1(); |
Reniboy | 1:775f6e8071a2 | 67 | if (g_sw2_flag) { |
Reniboy | 1:775f6e8071a2 | 68 | g_sw2_flag = 0; //clear the flag |
Reniboy | 1:775f6e8071a2 | 69 | buzzer.beep(1700,0.2); //make sound when selection is chosen |
Reniboy | 2:31c5c3b46742 | 70 | activeIn(); |
Reniboy | 0:e1ae1b9889a3 | 71 | beeping(); |
Reniboy | 2:31c5c3b46742 | 72 | |
Reniboy | 1:775f6e8071a2 | 73 | } |
Reniboy | 1:775f6e8071a2 | 74 | |
Reniboy | 2:31c5c3b46742 | 75 | |
Reniboy | 0:e1ae1b9889a3 | 76 | } |
Reniboy | 1:775f6e8071a2 | 77 | } |
Reniboy | 1:775f6e8071a2 | 78 | |
Reniboy | 1:775f6e8071a2 | 79 | |
Reniboy | 1:775f6e8071a2 | 80 | |
Reniboy | 0:e1ae1b9889a3 | 81 | } |
Reniboy | 0:e1ae1b9889a3 | 82 | float averageDistance() /** Divide the running total by 10 to get the average distance to get more accurate readings on the sensor**/ |
Reniboy | 0:e1ae1b9889a3 | 83 | { |
Reniboy | 0:e1ae1b9889a3 | 84 | int a = sensor.getDistanceCm(); |
Reniboy | 0:e1ae1b9889a3 | 85 | int b = sensor.getDistanceCm(); |
Reniboy | 0:e1ae1b9889a3 | 86 | int c = sensor.getDistanceCm(); |
Reniboy | 0:e1ae1b9889a3 | 87 | int d = sensor.getDistanceCm(); |
Reniboy | 0:e1ae1b9889a3 | 88 | int e = sensor.getDistanceCm(); |
Reniboy | 0:e1ae1b9889a3 | 89 | int f = sensor.getDistanceCm(); |
Reniboy | 0:e1ae1b9889a3 | 90 | int g = sensor.getDistanceCm(); |
Reniboy | 0:e1ae1b9889a3 | 91 | int h = sensor.getDistanceCm(); |
Reniboy | 0:e1ae1b9889a3 | 92 | int i = sensor.getDistanceCm(); |
Reniboy | 0:e1ae1b9889a3 | 93 | int j = sensor.getDistanceCm(); |
Reniboy | 0:e1ae1b9889a3 | 94 | |
Reniboy | 0:e1ae1b9889a3 | 95 | distance = (a+b+c+d+e+f+g+h+i+j)/10; |
Reniboy | 0:e1ae1b9889a3 | 96 | return distance; |
Reniboy | 0:e1ae1b9889a3 | 97 | } |
Reniboy | 0:e1ae1b9889a3 | 98 | float averageDistanceIn() /**Converting the distance from cm into inches **/ |
Reniboy | 0:e1ae1b9889a3 | 99 | { |
Reniboy | 1:775f6e8071a2 | 100 | distanceIn = distance*(0.394); //converting distance from cm into inches. |
Reniboy | 0:e1ae1b9889a3 | 101 | return distanceIn; |
Reniboy | 0:e1ae1b9889a3 | 102 | } |
Reniboy | 0:e1ae1b9889a3 | 103 | |
Reniboy | 0:e1ae1b9889a3 | 104 | |
Reniboy | 0:e1ae1b9889a3 | 105 | |
Reniboy | 0:e1ae1b9889a3 | 106 | |
Reniboy | 0:e1ae1b9889a3 | 107 | void beeping() |
Reniboy | 0:e1ae1b9889a3 | 108 | /* |
Reniboy | 0:e1ae1b9889a3 | 109 | @Brief Function to create the effect of varying beeping sounds depending on how close the sensor is to an object interspersed with |
Reniboy | 1:775f6e8071a2 | 110 | the led changing color depending on the distance |
Reniboy | 0:e1ae1b9889a3 | 111 | */ |
Reniboy | 0:e1ae1b9889a3 | 112 | { |
Reniboy | 1:775f6e8071a2 | 113 | int distance = averageDistance(); |
Reniboy | 0:e1ae1b9889a3 | 114 | |
Reniboy | 0:e1ae1b9889a3 | 115 | if (distance > 250.0) { |
Reniboy | 0:e1ae1b9889a3 | 116 | i = 1.4; |
Reniboy | 0:e1ae1b9889a3 | 117 | r_led = 1; |
Reniboy | 0:e1ae1b9889a3 | 118 | } |
Reniboy | 1:775f6e8071a2 | 119 | if (distance <= 250.0) { |
Reniboy | 0:e1ae1b9889a3 | 120 | i = 1.2; |
Reniboy | 0:e1ae1b9889a3 | 121 | r_led = 1; |
Reniboy | 0:e1ae1b9889a3 | 122 | } |
Reniboy | 1:775f6e8071a2 | 123 | if (distance < 200.0) { |
Reniboy | 0:e1ae1b9889a3 | 124 | i = 1; |
Reniboy | 0:e1ae1b9889a3 | 125 | r_led = 1; |
Reniboy | 0:e1ae1b9889a3 | 126 | |
Reniboy | 0:e1ae1b9889a3 | 127 | } |
Reniboy | 1:775f6e8071a2 | 128 | if (distance < 150) { |
Reniboy | 0:e1ae1b9889a3 | 129 | i = 0.7; |
Reniboy | 1:775f6e8071a2 | 130 | r_led = 1; //Allows the Led to change color depending on sensor distances |
Reniboy | 0:e1ae1b9889a3 | 131 | |
Reniboy | 0:e1ae1b9889a3 | 132 | } |
Reniboy | 1:775f6e8071a2 | 133 | if (distance < 100) { |
Reniboy | 0:e1ae1b9889a3 | 134 | i = 0.5; |
Reniboy | 0:e1ae1b9889a3 | 135 | r_led = 0; |
Reniboy | 0:e1ae1b9889a3 | 136 | |
Reniboy | 0:e1ae1b9889a3 | 137 | } |
Reniboy | 1:775f6e8071a2 | 138 | if (distance <= 50) { |
Reniboy | 0:e1ae1b9889a3 | 139 | i = 0.25; |
Reniboy | 0:e1ae1b9889a3 | 140 | r_led = 0; |
Reniboy | 0:e1ae1b9889a3 | 141 | |
Reniboy | 0:e1ae1b9889a3 | 142 | } |
Reniboy | 0:e1ae1b9889a3 | 143 | if (distance < 25) { |
Reniboy | 0:e1ae1b9889a3 | 144 | i = 0.05; |
Reniboy | 0:e1ae1b9889a3 | 145 | r_led = 0; |
Reniboy | 0:e1ae1b9889a3 | 146 | } |
Reniboy | 0:e1ae1b9889a3 | 147 | buzzer.beep(1000, 0.5); |
Reniboy | 0:e1ae1b9889a3 | 148 | wait(i); |
Reniboy | 0:e1ae1b9889a3 | 149 | buzzer.nobeep(); |
Reniboy | 0:e1ae1b9889a3 | 150 | wait(i); |
Reniboy | 0:e1ae1b9889a3 | 151 | } |
Reniboy | 0:e1ae1b9889a3 | 152 | |
Reniboy | 0:e1ae1b9889a3 | 153 | |
Reniboy | 0:e1ae1b9889a3 | 154 | |
Reniboy | 1:775f6e8071a2 | 155 | void sweep() //This function allows the radar to change direction with line across the screen and vary the speed with time param t. |
Reniboy | 0:e1ae1b9889a3 | 156 | { |
Reniboy | 0:e1ae1b9889a3 | 157 | int distance = averageDistance(); |
Reniboy | 0:e1ae1b9889a3 | 158 | char str[14]; |
Reniboy | 0:e1ae1b9889a3 | 159 | sprintf(str,"%i",distance); |
Reniboy | 1:775f6e8071a2 | 160 | |
Reniboy | 0:e1ae1b9889a3 | 161 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 162 | lcd.drawLine(42,47,4,36,1);// Fourth and final trace to the left |
Reniboy | 0:e1ae1b9889a3 | 163 | lcd.drawCircle(42,47,38,0); |
Reniboy | 0:e1ae1b9889a3 | 164 | lcd.drawCircle(42,47,26,0); |
Reniboy | 0:e1ae1b9889a3 | 165 | lcd.drawCircle(42,47,14,0); |
Reniboy | 0:e1ae1b9889a3 | 166 | lcd.drawCircle(42,47,2,0); |
Reniboy | 0:e1ae1b9889a3 | 167 | lcd.printString(str,1,0); |
Reniboy | 2:31c5c3b46742 | 168 | lcd.printString("cm",12,0); |
Reniboy | 0:e1ae1b9889a3 | 169 | |
Reniboy | 0:e1ae1b9889a3 | 170 | lcd.drawLine(0,47,83,47,1);//centre line |
Reniboy | 0:e1ae1b9889a3 | 171 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 172 | |
Reniboy | 0:e1ae1b9889a3 | 173 | } |
Reniboy | 0:e1ae1b9889a3 | 174 | void sweepOne() |
Reniboy | 0:e1ae1b9889a3 | 175 | { |
Reniboy | 0:e1ae1b9889a3 | 176 | int distance = averageDistance(); |
Reniboy | 0:e1ae1b9889a3 | 177 | char str[14]; |
Reniboy | 0:e1ae1b9889a3 | 178 | sprintf(str,"%i",distance); |
Reniboy | 0:e1ae1b9889a3 | 179 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 180 | lcd.drawLine(42,47,10,25,1);//Third trace to the left |
Reniboy | 0:e1ae1b9889a3 | 181 | lcd.drawCircle(42,47,38,0); |
Reniboy | 0:e1ae1b9889a3 | 182 | lcd.drawCircle(42,47,26,0); |
Reniboy | 0:e1ae1b9889a3 | 183 | lcd.drawCircle(42,47,14,0); |
Reniboy | 0:e1ae1b9889a3 | 184 | lcd.drawCircle(42,47,2,0); |
Reniboy | 0:e1ae1b9889a3 | 185 | lcd.drawLine(0,47,83,47,1);//centre line |
Reniboy | 0:e1ae1b9889a3 | 186 | lcd.printString(str,1,0); |
Reniboy | 2:31c5c3b46742 | 187 | lcd.printString("cm",12,0); |
Reniboy | 0:e1ae1b9889a3 | 188 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 189 | |
Reniboy | 0:e1ae1b9889a3 | 190 | } |
Reniboy | 0:e1ae1b9889a3 | 191 | |
Reniboy | 0:e1ae1b9889a3 | 192 | void sweepTwo() |
Reniboy | 0:e1ae1b9889a3 | 193 | { |
Reniboy | 0:e1ae1b9889a3 | 194 | int distance = averageDistance(); |
Reniboy | 0:e1ae1b9889a3 | 195 | char str[14]; |
Reniboy | 0:e1ae1b9889a3 | 196 | sprintf(str,"%i",distance); |
Reniboy | 0:e1ae1b9889a3 | 197 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 198 | lcd.drawLine(42,47,21,15,1);//Second Line to the left |
Reniboy | 0:e1ae1b9889a3 | 199 | lcd.drawCircle(42,47,38,0); |
Reniboy | 0:e1ae1b9889a3 | 200 | lcd.drawCircle(42,47,26,0); |
Reniboy | 0:e1ae1b9889a3 | 201 | lcd.drawCircle(42,47,14,0); |
Reniboy | 0:e1ae1b9889a3 | 202 | lcd.drawCircle(42,47,2,0); |
Reniboy | 0:e1ae1b9889a3 | 203 | lcd.drawLine(0,47,83,47,1);//centre line |
Reniboy | 0:e1ae1b9889a3 | 204 | lcd.printString(str,1,0); |
Reniboy | 2:31c5c3b46742 | 205 | lcd.printString("cm",12,0); |
Reniboy | 0:e1ae1b9889a3 | 206 | |
Reniboy | 0:e1ae1b9889a3 | 207 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 208 | } |
Reniboy | 0:e1ae1b9889a3 | 209 | |
Reniboy | 0:e1ae1b9889a3 | 210 | void sweepThree() |
Reniboy | 0:e1ae1b9889a3 | 211 | { |
Reniboy | 0:e1ae1b9889a3 | 212 | int distance = averageDistance(); |
Reniboy | 0:e1ae1b9889a3 | 213 | char str[14]; |
Reniboy | 0:e1ae1b9889a3 | 214 | sprintf(str,"%i",distance); |
Reniboy | 0:e1ae1b9889a3 | 215 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 216 | lcd.drawLine(42,47,32,11,1);//First Line to the left |
Reniboy | 0:e1ae1b9889a3 | 217 | lcd.drawCircle(42,47,38,0); |
Reniboy | 0:e1ae1b9889a3 | 218 | lcd.drawCircle(42,47,26,0); |
Reniboy | 0:e1ae1b9889a3 | 219 | lcd.drawCircle(42,47,14,0); |
Reniboy | 1:775f6e8071a2 | 220 | lcd.drawCircle(42,47,2,0); |
Reniboy | 0:e1ae1b9889a3 | 221 | lcd.drawLine(0,47,83,47,1);//centre line |
Reniboy | 0:e1ae1b9889a3 | 222 | lcd.printString(str,1,0); |
Reniboy | 2:31c5c3b46742 | 223 | lcd.printString("cm",12,0); |
Reniboy | 0:e1ae1b9889a3 | 224 | |
Reniboy | 0:e1ae1b9889a3 | 225 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 226 | |
Reniboy | 0:e1ae1b9889a3 | 227 | } |
Reniboy | 0:e1ae1b9889a3 | 228 | |
Reniboy | 0:e1ae1b9889a3 | 229 | void sweepFour() |
Reniboy | 0:e1ae1b9889a3 | 230 | { |
Reniboy | 0:e1ae1b9889a3 | 231 | int distance = averageDistance(); |
Reniboy | 0:e1ae1b9889a3 | 232 | char str[14]; |
Reniboy | 0:e1ae1b9889a3 | 233 | sprintf(str,"%i",distance); |
Reniboy | 0:e1ae1b9889a3 | 234 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 235 | lcd.drawLine(42,47,42,9,1); |
Reniboy | 0:e1ae1b9889a3 | 236 | lcd.drawCircle(42,47,38,0); |
Reniboy | 0:e1ae1b9889a3 | 237 | lcd.drawCircle(42,47,26,0); |
Reniboy | 0:e1ae1b9889a3 | 238 | lcd.drawCircle(42,47,14,0); |
Reniboy | 0:e1ae1b9889a3 | 239 | lcd.drawCircle(42,47,2,0); |
Reniboy | 0:e1ae1b9889a3 | 240 | lcd.drawLine(0,47,83,47,1);//centre line |
Reniboy | 0:e1ae1b9889a3 | 241 | lcd.printString(str,1,0); |
Reniboy | 2:31c5c3b46742 | 242 | lcd.printString("cm",12,0); |
Reniboy | 2:31c5c3b46742 | 243 | |
Reniboy | 0:e1ae1b9889a3 | 244 | |
Reniboy | 0:e1ae1b9889a3 | 245 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 246 | } |
Reniboy | 0:e1ae1b9889a3 | 247 | void sweepFive() |
Reniboy | 0:e1ae1b9889a3 | 248 | { |
Reniboy | 0:e1ae1b9889a3 | 249 | int distance = averageDistance(); |
Reniboy | 0:e1ae1b9889a3 | 250 | char str[14]; |
Reniboy | 0:e1ae1b9889a3 | 251 | sprintf(str,"%i",distance); |
Reniboy | 1:775f6e8071a2 | 252 | lcd.clear(); |
Reniboy | 1:775f6e8071a2 | 253 | lcd.drawLine(0,47,83,47,1);//centre line |
Reniboy | 1:775f6e8071a2 | 254 | lcd.drawLine(42,47,42,9,1); |
Reniboy | 1:775f6e8071a2 | 255 | lcd.drawCircle(42,47,38,0); |
Reniboy | 1:775f6e8071a2 | 256 | lcd.drawCircle(42,47,26,0); |
Reniboy | 1:775f6e8071a2 | 257 | lcd.drawCircle(42,47,14,0); |
Reniboy | 1:775f6e8071a2 | 258 | lcd.drawCircle(42,47,2,0); |
Reniboy | 1:775f6e8071a2 | 259 | lcd.printString(str,1,0); |
Reniboy | 2:31c5c3b46742 | 260 | lcd.printString("cm",12,0); |
Reniboy | 0:e1ae1b9889a3 | 261 | |
Reniboy | 1:775f6e8071a2 | 262 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 263 | |
Reniboy | 0:e1ae1b9889a3 | 264 | } |
Reniboy | 0:e1ae1b9889a3 | 265 | void sweepSix() |
Reniboy | 0:e1ae1b9889a3 | 266 | { |
Reniboy | 0:e1ae1b9889a3 | 267 | int distance = averageDistance(); |
Reniboy | 0:e1ae1b9889a3 | 268 | char str[14]; |
Reniboy | 0:e1ae1b9889a3 | 269 | sprintf(str,"%i",distance); |
Reniboy | 0:e1ae1b9889a3 | 270 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 271 | lcd.drawLine(42,47,52,11,1);//First line to the right |
Reniboy | 0:e1ae1b9889a3 | 272 | lcd.drawLine(0,47,83,47,1);//centre line |
Reniboy | 0:e1ae1b9889a3 | 273 | lcd.drawCircle(42,47,38,0); |
Reniboy | 0:e1ae1b9889a3 | 274 | lcd.drawCircle(42,47,26,0); |
Reniboy | 0:e1ae1b9889a3 | 275 | lcd.drawCircle(42,47,14,0); |
Reniboy | 0:e1ae1b9889a3 | 276 | lcd.drawCircle(42,47,2,0); |
Reniboy | 0:e1ae1b9889a3 | 277 | lcd.printString(str,1,0); |
Reniboy | 2:31c5c3b46742 | 278 | lcd.printString("cm",12,0); |
Reniboy | 0:e1ae1b9889a3 | 279 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 280 | } |
Reniboy | 0:e1ae1b9889a3 | 281 | |
Reniboy | 0:e1ae1b9889a3 | 282 | void sweepSeven() |
Reniboy | 0:e1ae1b9889a3 | 283 | { |
Reniboy | 0:e1ae1b9889a3 | 284 | int distance = averageDistance(); |
Reniboy | 0:e1ae1b9889a3 | 285 | char str[14]; |
Reniboy | 0:e1ae1b9889a3 | 286 | sprintf(str,"%i",distance); |
Reniboy | 0:e1ae1b9889a3 | 287 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 288 | lcd.drawLine(42,47,63,15,1);//Second Line to the right |
Reniboy | 0:e1ae1b9889a3 | 289 | lcd.drawLine(0,47,83,47,1);//centre line |
Reniboy | 0:e1ae1b9889a3 | 290 | lcd.drawCircle(42,47,38,0); |
Reniboy | 0:e1ae1b9889a3 | 291 | lcd.drawCircle(42,47,26,0); |
Reniboy | 0:e1ae1b9889a3 | 292 | lcd.drawCircle(42,47,14,0); |
Reniboy | 0:e1ae1b9889a3 | 293 | lcd.drawCircle(42,47,2,0); |
Reniboy | 0:e1ae1b9889a3 | 294 | lcd.printString(str,1,0); |
Reniboy | 2:31c5c3b46742 | 295 | lcd.printString("cm",12,0); |
Reniboy | 0:e1ae1b9889a3 | 296 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 297 | } |
Reniboy | 0:e1ae1b9889a3 | 298 | |
Reniboy | 0:e1ae1b9889a3 | 299 | void sweepEight() |
Reniboy | 0:e1ae1b9889a3 | 300 | { |
Reniboy | 0:e1ae1b9889a3 | 301 | int distance = averageDistance(); |
Reniboy | 0:e1ae1b9889a3 | 302 | char str[14]; |
Reniboy | 0:e1ae1b9889a3 | 303 | sprintf(str,"%i",distance); |
Reniboy | 0:e1ae1b9889a3 | 304 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 305 | lcd.drawLine(42,47,74,25,1);//Third trace on the right |
Reniboy | 0:e1ae1b9889a3 | 306 | lcd.drawLine(0,47,83,47,1);//centre line |
Reniboy | 0:e1ae1b9889a3 | 307 | lcd.drawCircle(42,47,38,0); |
Reniboy | 0:e1ae1b9889a3 | 308 | lcd.drawCircle(42,47,26,0); |
Reniboy | 0:e1ae1b9889a3 | 309 | lcd.drawCircle(42,47,14,0); |
Reniboy | 0:e1ae1b9889a3 | 310 | lcd.printString(str,1,0); |
Reniboy | 2:31c5c3b46742 | 311 | lcd.printString("cm",12,0); |
Reniboy | 1:775f6e8071a2 | 312 | |
Reniboy | 0:e1ae1b9889a3 | 313 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 314 | } |
Reniboy | 0:e1ae1b9889a3 | 315 | |
Reniboy | 0:e1ae1b9889a3 | 316 | void sweepNine() |
Reniboy | 0:e1ae1b9889a3 | 317 | { |
Reniboy | 0:e1ae1b9889a3 | 318 | int distance = averageDistance(); |
Reniboy | 0:e1ae1b9889a3 | 319 | char str[14]; |
Reniboy | 0:e1ae1b9889a3 | 320 | sprintf(str,"%i",distance); |
Reniboy | 0:e1ae1b9889a3 | 321 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 322 | lcd.drawCircle(42,47,38,0); |
Reniboy | 0:e1ae1b9889a3 | 323 | lcd.drawCircle(42,47,26,0); |
Reniboy | 0:e1ae1b9889a3 | 324 | lcd.drawCircle(42,47,14,0); |
Reniboy | 0:e1ae1b9889a3 | 325 | lcd.drawCircle(42,47,2,0); |
Reniboy | 0:e1ae1b9889a3 | 326 | |
Reniboy | 0:e1ae1b9889a3 | 327 | lcd.drawLine(42,47,80,36,1);//Fourth trace to the right |
Reniboy | 0:e1ae1b9889a3 | 328 | lcd.drawLine(0,47,83,47,1);//centre line |
Reniboy | 0:e1ae1b9889a3 | 329 | lcd.printString(str,1,0); |
Reniboy | 2:31c5c3b46742 | 330 | lcd.printString("cm",12,0); |
Reniboy | 0:e1ae1b9889a3 | 331 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 332 | } |
Reniboy | 0:e1ae1b9889a3 | 333 | |
Reniboy | 1:775f6e8071a2 | 334 | void sensingImage() /** @brief Function to allow the sensor to read distance in classic mode in centimetres and draw subsequent visual indication on the screen **/ |
Reniboy | 0:e1ae1b9889a3 | 335 | |
Reniboy | 0:e1ae1b9889a3 | 336 | { |
Reniboy | 0:e1ae1b9889a3 | 337 | int distance = averageDistance(); |
Reniboy | 0:e1ae1b9889a3 | 338 | char str[14]; |
Reniboy | 0:e1ae1b9889a3 | 339 | sprintf(str,"%i",distance); |
Reniboy | 0:e1ae1b9889a3 | 340 | |
Reniboy | 0:e1ae1b9889a3 | 341 | |
Reniboy | 0:e1ae1b9889a3 | 342 | |
Reniboy | 0:e1ae1b9889a3 | 343 | if (distance>250) { |
Reniboy | 0:e1ae1b9889a3 | 344 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 345 | lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 346 | lcd.drawRect(78.5,19,4.5,12,1); |
Reniboy | 0:e1ae1b9889a3 | 347 | lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right |
Reniboy | 2:31c5c3b46742 | 348 | lcd.printString("cm",46,2.5); |
Reniboy | 0:e1ae1b9889a3 | 349 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 350 | } |
Reniboy | 0:e1ae1b9889a3 | 351 | if (distance<=250) { |
Reniboy | 0:e1ae1b9889a3 | 352 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 353 | lcd.drawRect(7,15.5,5.5,18,1); // fourth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 354 | lcd.drawRect(71.5,15.5,5.5,18,1); // fourth rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 355 | lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 356 | lcd.drawRect(78.5,19,4.5,12,1); |
Reniboy | 0:e1ae1b9889a3 | 357 | lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right |
Reniboy | 2:31c5c3b46742 | 358 | lcd.printString("cm",46,2.5); |
Reniboy | 0:e1ae1b9889a3 | 359 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 360 | } |
Reniboy | 0:e1ae1b9889a3 | 361 | if (distance< 100) { |
Reniboy | 0:e1ae1b9889a3 | 362 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 363 | lcd.drawRect(14,12,5.5,24,1); // third rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 364 | lcd.drawRect(64.5,12,5.5,24,1); // third rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 365 | lcd.drawRect(7,15.5,5.5,18,1); // fourth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 366 | lcd.drawRect(71.5,15.5,5.5,18,1); // fourth rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 367 | lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 368 | lcd.drawRect(78.5,19,4.5,12,1); |
Reniboy | 0:e1ae1b9889a3 | 369 | lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right |
Reniboy | 2:31c5c3b46742 | 370 | lcd.printString("cm",46,2.5); |
Reniboy | 0:e1ae1b9889a3 | 371 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 372 | |
Reniboy | 0:e1ae1b9889a3 | 373 | } |
Reniboy | 0:e1ae1b9889a3 | 374 | if (distance < 40) { |
Reniboy | 0:e1ae1b9889a3 | 375 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 376 | lcd.drawRect(21,8.5,5.5,30,1); // second rectangle on the left |
Reniboy | 0:e1ae1b9889a3 | 377 | lcd.drawRect(57.5,8.5,5.5,30,1);//second rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 378 | lcd.drawRect(14,12,5.5,24,1); // third rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 379 | lcd.drawRect(64.5,12,5.5,24,1); // third rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 380 | lcd.drawRect(7,15.5,5.5,18,1); // fourth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 381 | lcd.drawRect(71.5,15.5,5.5,18,1); // fourth rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 382 | lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 383 | lcd.drawRect(78.5,19,4.5,12,1); |
Reniboy | 0:e1ae1b9889a3 | 384 | lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right |
Reniboy | 2:31c5c3b46742 | 385 | lcd.printString("cm",46,2.5); |
Reniboy | 0:e1ae1b9889a3 | 386 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 387 | |
Reniboy | 0:e1ae1b9889a3 | 388 | |
Reniboy | 0:e1ae1b9889a3 | 389 | |
Reniboy | 0:e1ae1b9889a3 | 390 | } |
Reniboy | 0:e1ae1b9889a3 | 391 | if (distance < 20.0) { |
Reniboy | 0:e1ae1b9889a3 | 392 | |
Reniboy | 0:e1ae1b9889a3 | 393 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 394 | lcd.drawRect(28,5,5.5,36,1); //first rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 395 | lcd.drawRect(50.5,5,5.5,36,1); // first rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 396 | lcd.drawRect(21,8.5,5.5,30,1); // second rectangle on the left |
Reniboy | 0:e1ae1b9889a3 | 397 | lcd.drawRect(57.5,8.5,5.5,30,1);//second rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 398 | lcd.drawRect(14,12,5.5,24,1); // third rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 399 | lcd.drawRect(64.5,12,5.5,24,1); // third rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 400 | lcd.drawRect(7,15.5,5.5,18,1); // fourth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 401 | lcd.drawRect(71.5,15.5,5.5,18,1); // fourth rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 402 | lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 403 | lcd.drawRect(78.5,19,4.5,12,1); |
Reniboy | 0:e1ae1b9889a3 | 404 | lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right |
Reniboy | 2:31c5c3b46742 | 405 | lcd.printString("cm",46,2.5); |
Reniboy | 0:e1ae1b9889a3 | 406 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 407 | } |
Reniboy | 0:e1ae1b9889a3 | 408 | |
Reniboy | 0:e1ae1b9889a3 | 409 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 410 | |
Reniboy | 0:e1ae1b9889a3 | 411 | } |
Reniboy | 1:775f6e8071a2 | 412 | void sensingImageIn() /**Function to allow the sensor to read distance in classic mode in inches and provides visual indication also **/ |
Reniboy | 0:e1ae1b9889a3 | 413 | |
Reniboy | 0:e1ae1b9889a3 | 414 | { |
Reniboy | 0:e1ae1b9889a3 | 415 | int distanceIn = averageDistanceIn(); |
Reniboy | 0:e1ae1b9889a3 | 416 | char str[14]; |
Reniboy | 1:775f6e8071a2 | 417 | sprintf(str,"%i",distanceIn); |
Reniboy | 0:e1ae1b9889a3 | 418 | |
Reniboy | 0:e1ae1b9889a3 | 419 | |
Reniboy | 0:e1ae1b9889a3 | 420 | |
Reniboy | 0:e1ae1b9889a3 | 421 | if (distance>250) { |
Reniboy | 0:e1ae1b9889a3 | 422 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 423 | lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 424 | lcd.drawRect(78.5,19,4.5,12,1); |
Reniboy | 0:e1ae1b9889a3 | 425 | lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right |
Reniboy | 2:31c5c3b46742 | 426 | lcd.printString("in",46,2.5); |
Reniboy | 0:e1ae1b9889a3 | 427 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 428 | } |
Reniboy | 0:e1ae1b9889a3 | 429 | if (distance<=250) { |
Reniboy | 0:e1ae1b9889a3 | 430 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 431 | lcd.drawRect(7,15.5,5.5,18,1); // fourth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 432 | lcd.drawRect(71.5,15.5,5.5,18,1); // fourth rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 433 | lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 434 | lcd.drawRect(78.5,19,4.5,12,1); |
Reniboy | 0:e1ae1b9889a3 | 435 | lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right |
Reniboy | 2:31c5c3b46742 | 436 | lcd.printString("in",46,2.5); |
Reniboy | 0:e1ae1b9889a3 | 437 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 438 | } |
Reniboy | 0:e1ae1b9889a3 | 439 | if (distance< 100) { |
Reniboy | 0:e1ae1b9889a3 | 440 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 441 | lcd.drawRect(14,12,5.5,24,1); // third rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 442 | lcd.drawRect(64.5,12,5.5,24,1); // third rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 443 | lcd.drawRect(7,15.5,5.5,18,1); // fourth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 444 | lcd.drawRect(71.5,15.5,5.5,18,1); // fourth rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 445 | lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 446 | lcd.drawRect(78.5,19,4.5,12,1); |
Reniboy | 0:e1ae1b9889a3 | 447 | lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right |
Reniboy | 2:31c5c3b46742 | 448 | lcd.printString("in",46,2.5); |
Reniboy | 0:e1ae1b9889a3 | 449 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 450 | |
Reniboy | 0:e1ae1b9889a3 | 451 | } |
Reniboy | 0:e1ae1b9889a3 | 452 | if (distance < 40) { |
Reniboy | 0:e1ae1b9889a3 | 453 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 454 | lcd.drawRect(21,8.5,5.5,30,1); // second rectangle on the left |
Reniboy | 0:e1ae1b9889a3 | 455 | lcd.drawRect(57.5,8.5,5.5,30,1);//second rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 456 | lcd.drawRect(14,12,5.5,24,1); // third rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 457 | lcd.drawRect(64.5,12,5.5,24,1); // third rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 458 | lcd.drawRect(7,15.5,5.5,18,1); // fourth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 459 | lcd.drawRect(71.5,15.5,5.5,18,1); // fourth rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 460 | lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 461 | lcd.drawRect(78.5,19,4.5,12,1); |
Reniboy | 0:e1ae1b9889a3 | 462 | lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right |
Reniboy | 2:31c5c3b46742 | 463 | lcd.printString("in",46,2.5); |
Reniboy | 0:e1ae1b9889a3 | 464 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 465 | |
Reniboy | 0:e1ae1b9889a3 | 466 | |
Reniboy | 0:e1ae1b9889a3 | 467 | |
Reniboy | 0:e1ae1b9889a3 | 468 | } |
Reniboy | 0:e1ae1b9889a3 | 469 | if (distance < 20.0) { |
Reniboy | 0:e1ae1b9889a3 | 470 | |
Reniboy | 0:e1ae1b9889a3 | 471 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 472 | lcd.drawRect(28,5,5.5,36,1); //first rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 473 | lcd.drawRect(50.5,5,5.5,36,1); // first rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 474 | lcd.drawRect(21,8.5,5.5,30,1); // second rectangle on the left |
Reniboy | 0:e1ae1b9889a3 | 475 | lcd.drawRect(57.5,8.5,5.5,30,1);//second rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 476 | lcd.drawRect(14,12,5.5,24,1); // third rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 477 | lcd.drawRect(64.5,12,5.5,24,1); // third rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 478 | lcd.drawRect(7,15.5,5.5,18,1); // fourth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 479 | lcd.drawRect(71.5,15.5,5.5,18,1); // fourth rectangle to the right |
Reniboy | 0:e1ae1b9889a3 | 480 | lcd.drawRect(1,19,4.5,12,1); //plot of fifth rectangle to the left |
Reniboy | 0:e1ae1b9889a3 | 481 | lcd.drawRect(78.5,19,4.5,12,1); |
Reniboy | 0:e1ae1b9889a3 | 482 | lcd.printString(str,35.5,2.5); // plot of fifth rectangle to the right |
Reniboy | 2:31c5c3b46742 | 483 | lcd.printString("in",46,2.5); |
Reniboy | 0:e1ae1b9889a3 | 484 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 485 | } |
Reniboy | 0:e1ae1b9889a3 | 486 | |
Reniboy | 0:e1ae1b9889a3 | 487 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 488 | |
Reniboy | 0:e1ae1b9889a3 | 489 | } |
Reniboy | 0:e1ae1b9889a3 | 490 | |
Reniboy | 0:e1ae1b9889a3 | 491 | |
Reniboy | 0:e1ae1b9889a3 | 492 | |
Reniboy | 0:e1ae1b9889a3 | 493 | |
Reniboy | 0:e1ae1b9889a3 | 494 | void sweepSpeed() |
Reniboy | 1:775f6e8071a2 | 495 | /**@Brief Function to create the effect of sweep speeds depending on how close the sensor is to an object **/ |
Reniboy | 0:e1ae1b9889a3 | 496 | { |
Reniboy | 1:775f6e8071a2 | 497 | |
Reniboy | 1:775f6e8071a2 | 498 | int distance = averageDistance(); |
Reniboy | 0:e1ae1b9889a3 | 499 | char str[14]; |
Reniboy | 0:e1ae1b9889a3 | 500 | sprintf(str,"%i",distance); |
Reniboy | 0:e1ae1b9889a3 | 501 | |
Reniboy | 0:e1ae1b9889a3 | 502 | |
Reniboy | 0:e1ae1b9889a3 | 503 | if (distance>250.0) { |
Reniboy | 2:31c5c3b46742 | 504 | t = 0.6; |
Reniboy | 1:775f6e8071a2 | 505 | |
Reniboy | 0:e1ae1b9889a3 | 506 | } |
Reniboy | 0:e1ae1b9889a3 | 507 | if (distance<=200.0) { |
Reniboy | 2:31c5c3b46742 | 508 | t = 0.5; |
Reniboy | 1:775f6e8071a2 | 509 | |
Reniboy | 0:e1ae1b9889a3 | 510 | } |
Reniboy | 0:e1ae1b9889a3 | 511 | if (distance<100.0) { |
Reniboy | 2:31c5c3b46742 | 512 | t = 0.4; |
Reniboy | 1:775f6e8071a2 | 513 | |
Reniboy | 0:e1ae1b9889a3 | 514 | |
Reniboy | 0:e1ae1b9889a3 | 515 | } |
Reniboy | 0:e1ae1b9889a3 | 516 | if (distance<80) { |
Reniboy | 0:e1ae1b9889a3 | 517 | t = 0.8; |
Reniboy | 1:775f6e8071a2 | 518 | |
Reniboy | 0:e1ae1b9889a3 | 519 | |
Reniboy | 0:e1ae1b9889a3 | 520 | } |
Reniboy | 0:e1ae1b9889a3 | 521 | if (distance<60) { |
Reniboy | 2:31c5c3b46742 | 522 | t = 0.2; |
Reniboy | 1:775f6e8071a2 | 523 | |
Reniboy | 0:e1ae1b9889a3 | 524 | |
Reniboy | 0:e1ae1b9889a3 | 525 | } |
Reniboy | 0:e1ae1b9889a3 | 526 | if (distance<40) { |
Reniboy | 2:31c5c3b46742 | 527 | t = 0.1; |
Reniboy | 1:775f6e8071a2 | 528 | lcd.printString(str,1,0); |
Reniboy | 0:e1ae1b9889a3 | 529 | |
Reniboy | 0:e1ae1b9889a3 | 530 | } |
Reniboy | 0:e1ae1b9889a3 | 531 | if (distance<20) { |
Reniboy | 2:31c5c3b46742 | 532 | t = 0.05; |
Reniboy | 1:775f6e8071a2 | 533 | lcd.printString(str,1,0); |
Reniboy | 0:e1ae1b9889a3 | 534 | } |
Reniboy | 1:775f6e8071a2 | 535 | |
Reniboy | 0:e1ae1b9889a3 | 536 | sweep(); |
Reniboy | 0:e1ae1b9889a3 | 537 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 538 | sweepOne(); |
Reniboy | 0:e1ae1b9889a3 | 539 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 540 | sweepTwo(); |
Reniboy | 0:e1ae1b9889a3 | 541 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 542 | sweepThree(); |
Reniboy | 0:e1ae1b9889a3 | 543 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 544 | sweepFour(); |
Reniboy | 0:e1ae1b9889a3 | 545 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 546 | sweepFive(); |
Reniboy | 0:e1ae1b9889a3 | 547 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 548 | sweepSix(); |
Reniboy | 0:e1ae1b9889a3 | 549 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 550 | sweepSeven(); |
Reniboy | 0:e1ae1b9889a3 | 551 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 552 | sweepEight(); |
Reniboy | 0:e1ae1b9889a3 | 553 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 554 | sweepNine(); |
Reniboy | 0:e1ae1b9889a3 | 555 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 556 | sweepEight(); |
Reniboy | 0:e1ae1b9889a3 | 557 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 558 | sweepSeven(); |
Reniboy | 0:e1ae1b9889a3 | 559 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 560 | sweepSix(); |
Reniboy | 0:e1ae1b9889a3 | 561 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 562 | sweepFive(); |
Reniboy | 0:e1ae1b9889a3 | 563 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 564 | sweepFour(); |
Reniboy | 0:e1ae1b9889a3 | 565 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 566 | sweepThree(); |
Reniboy | 0:e1ae1b9889a3 | 567 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 568 | sweepTwo(); |
Reniboy | 0:e1ae1b9889a3 | 569 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 570 | sweepOne(); |
Reniboy | 0:e1ae1b9889a3 | 571 | wait(t); |
Reniboy | 0:e1ae1b9889a3 | 572 | sweep(); |
Reniboy | 1:775f6e8071a2 | 573 | |
Reniboy | 0:e1ae1b9889a3 | 574 | |
Reniboy | 0:e1ae1b9889a3 | 575 | |
Reniboy | 0:e1ae1b9889a3 | 576 | |
Reniboy | 0:e1ae1b9889a3 | 577 | } |
Reniboy | 0:e1ae1b9889a3 | 578 | |
Reniboy | 0:e1ae1b9889a3 | 579 | |
Reniboy | 0:e1ae1b9889a3 | 580 | |
Reniboy | 1:775f6e8071a2 | 581 | void active() //Function containing the parking sensor measurements in cm |
Reniboy | 0:e1ae1b9889a3 | 582 | |
Reniboy | 0:e1ae1b9889a3 | 583 | { |
Reniboy | 2:31c5c3b46742 | 584 | sw3.mode(PullNone); |
Reniboy | 2:31c5c3b46742 | 585 | sw3.fall(&sw3_isr); |
Reniboy | 0:e1ae1b9889a3 | 586 | lcd.clear(); |
Reniboy | 1:775f6e8071a2 | 587 | ticker.attach(&timer_isr,1); //Ticker is attached to call function at specified rate of evry 0.5 seconds |
Reniboy | 0:e1ae1b9889a3 | 588 | while (1) { |
Reniboy | 0:e1ae1b9889a3 | 589 | if (g_timer_flag) { |
Reniboy | 0:e1ae1b9889a3 | 590 | g_timer_flag = 0; |
Reniboy | 0:e1ae1b9889a3 | 591 | sensingImage(); |
Reniboy | 0:e1ae1b9889a3 | 592 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 593 | beeping(); |
Reniboy | 0:e1ae1b9889a3 | 594 | } |
Reniboy | 1:775f6e8071a2 | 595 | if (g_sw3_flag) { //Allows the sw2 to interrupt and call the main function when the back sw2 is pressed. |
Reniboy | 0:e1ae1b9889a3 | 596 | g_sw3_flag = 0; |
Reniboy | 1:775f6e8071a2 | 597 | ticker.detach(); |
Reniboy | 0:e1ae1b9889a3 | 598 | mainProg(); |
Reniboy | 1:775f6e8071a2 | 599 | |
Reniboy | 1:775f6e8071a2 | 600 | } |
Reniboy | 1:775f6e8071a2 | 601 | |
Reniboy | 0:e1ae1b9889a3 | 602 | |
Reniboy | 0:e1ae1b9889a3 | 603 | |
Reniboy | 0:e1ae1b9889a3 | 604 | sleep(); //Allows the sensor to sleep when not calling the function to save power. |
Reniboy | 0:e1ae1b9889a3 | 605 | } |
Reniboy | 0:e1ae1b9889a3 | 606 | |
Reniboy | 0:e1ae1b9889a3 | 607 | } |
Reniboy | 1:775f6e8071a2 | 608 | void activeIn() //Function containing the implementation of the parking sensor function in inches |
Reniboy | 0:e1ae1b9889a3 | 609 | |
Reniboy | 0:e1ae1b9889a3 | 610 | { |
Reniboy | 2:31c5c3b46742 | 611 | sw3.mode(PullNone); |
Reniboy | 2:31c5c3b46742 | 612 | sw3.fall(&sw3_isr); |
Reniboy | 0:e1ae1b9889a3 | 613 | lcd.clear(); |
Reniboy | 1:775f6e8071a2 | 614 | ticker3.attach(&timer_isr,1); |
Reniboy | 0:e1ae1b9889a3 | 615 | while (1) { |
Reniboy | 0:e1ae1b9889a3 | 616 | if (g_timer_flag) { |
Reniboy | 2:31c5c3b46742 | 617 | g_timer_flag = 0; //if it has, clear the flag |
Reniboy | 0:e1ae1b9889a3 | 618 | sensingImageIn(); |
Reniboy | 0:e1ae1b9889a3 | 619 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 620 | beeping(); |
Reniboy | 0:e1ae1b9889a3 | 621 | } |
Reniboy | 0:e1ae1b9889a3 | 622 | if (g_sw3_flag) { //Allows the button to interrupt and call the main function when the back button is pressed. |
Reniboy | 0:e1ae1b9889a3 | 623 | g_sw3_flag = 0; |
Reniboy | 1:775f6e8071a2 | 624 | ticker3.detach(); |
Reniboy | 0:e1ae1b9889a3 | 625 | mainProg(); |
Reniboy | 1:775f6e8071a2 | 626 | |
Reniboy | 1:775f6e8071a2 | 627 | } |
Reniboy | 1:775f6e8071a2 | 628 | |
Reniboy | 0:e1ae1b9889a3 | 629 | |
Reniboy | 0:e1ae1b9889a3 | 630 | |
Reniboy | 0:e1ae1b9889a3 | 631 | sleep(); //Allows the sensor to sleep when not calling the function to save power. |
Reniboy | 0:e1ae1b9889a3 | 632 | } |
Reniboy | 0:e1ae1b9889a3 | 633 | |
Reniboy | 0:e1ae1b9889a3 | 634 | } |
Reniboy | 0:e1ae1b9889a3 | 635 | |
Reniboy | 0:e1ae1b9889a3 | 636 | void radar() |
Reniboy | 0:e1ae1b9889a3 | 637 | { |
Reniboy | 2:31c5c3b46742 | 638 | sw3.mode(PullNone); |
Reniboy | 2:31c5c3b46742 | 639 | sw3.fall(&sw3_isr); |
Reniboy | 1:775f6e8071a2 | 640 | lcd.clear(); |
Reniboy | 1:775f6e8071a2 | 641 | ticker2.attach(&timer_isr,0.5); //Sets another interrupt based system where the function is called periodically. |
Reniboy | 0:e1ae1b9889a3 | 642 | while(1) { |
Reniboy | 1:775f6e8071a2 | 643 | if (g_timer_flag) { |
Reniboy | 0:e1ae1b9889a3 | 644 | g_timer_flag = 0; |
Reniboy | 0:e1ae1b9889a3 | 645 | sweepSpeed(); |
Reniboy | 0:e1ae1b9889a3 | 646 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 647 | beeping(); |
Reniboy | 0:e1ae1b9889a3 | 648 | } |
Reniboy | 0:e1ae1b9889a3 | 649 | if (g_sw3_flag) { //Allows the button to interrupt and call the main function when the back button is pressed. |
Reniboy | 0:e1ae1b9889a3 | 650 | g_sw3_flag = 0; |
Reniboy | 1:775f6e8071a2 | 651 | ticker2.detach(); |
Reniboy | 0:e1ae1b9889a3 | 652 | mainProg(); |
Reniboy | 1:775f6e8071a2 | 653 | |
Reniboy | 1:775f6e8071a2 | 654 | } |
Reniboy | 0:e1ae1b9889a3 | 655 | sleep(); |
Reniboy | 0:e1ae1b9889a3 | 656 | } |
Reniboy | 0:e1ae1b9889a3 | 657 | |
Reniboy | 0:e1ae1b9889a3 | 658 | } |
Reniboy | 0:e1ae1b9889a3 | 659 | |
Reniboy | 0:e1ae1b9889a3 | 660 | |
Reniboy | 0:e1ae1b9889a3 | 661 | void introTune() /**@Brief Function defining introductory message **/ |
Reniboy | 0:e1ae1b9889a3 | 662 | { |
Reniboy | 0:e1ae1b9889a3 | 663 | |
Reniboy | 0:e1ae1b9889a3 | 664 | buzzer.beep(350,1);//F |
Reniboy | 0:e1ae1b9889a3 | 665 | wait(0.2); |
Reniboy | 0:e1ae1b9889a3 | 666 | buzzer.beep(262,1);//C |
Reniboy | 0:e1ae1b9889a3 | 667 | wait(0.2); |
Reniboy | 0:e1ae1b9889a3 | 668 | buzzer.beep(294,1);//D |
Reniboy | 0:e1ae1b9889a3 | 669 | wait(0.2); |
Reniboy | 0:e1ae1b9889a3 | 670 | buzzer.beep(350,0.5);//F |
Reniboy | 0:e1ae1b9889a3 | 671 | wait(0.2); |
Reniboy | 0:e1ae1b9889a3 | 672 | buzzer.beep(350,0.5); |
Reniboy | 0:e1ae1b9889a3 | 673 | wait(0.2); |
Reniboy | 0:e1ae1b9889a3 | 674 | buzzer.beep(262,1); |
Reniboy | 0:e1ae1b9889a3 | 675 | wait(0.2); |
Reniboy | 0:e1ae1b9889a3 | 676 | buzzer.beep(294,1); |
Reniboy | 0:e1ae1b9889a3 | 677 | wait(0.2); |
Reniboy | 0:e1ae1b9889a3 | 678 | buzzer.beep(350,1); |
Reniboy | 0:e1ae1b9889a3 | 679 | wait(0.2); |
Reniboy | 0:e1ae1b9889a3 | 680 | } |
Reniboy | 0:e1ae1b9889a3 | 681 | |
Reniboy | 0:e1ae1b9889a3 | 682 | |
Reniboy | 0:e1ae1b9889a3 | 683 | |
Reniboy | 0:e1ae1b9889a3 | 684 | void classicMode() /** @brief Function to print on the screen when no selection is chosen **/ |
Reniboy | 0:e1ae1b9889a3 | 685 | { |
Reniboy | 0:e1ae1b9889a3 | 686 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 687 | lcd.printString("SELECT A MODE:",0,0.5); |
Reniboy | 0:e1ae1b9889a3 | 688 | lcd.printString("CLASSIC (cm)", 11,2); |
Reniboy | 0:e1ae1b9889a3 | 689 | lcd.printString("RADAR MODE",11,3); |
Reniboy | 0:e1ae1b9889a3 | 690 | lcd.printString("CLASSIC (in)",11,4); |
Reniboy | 0:e1ae1b9889a3 | 691 | lcd.drawCircle(3,19.5,3,1); |
Reniboy | 0:e1ae1b9889a3 | 692 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 693 | |
Reniboy | 0:e1ae1b9889a3 | 694 | } |
Reniboy | 0:e1ae1b9889a3 | 695 | |
Reniboy | 0:e1ae1b9889a3 | 696 | |
Reniboy | 0:e1ae1b9889a3 | 697 | void radarMode() |
Reniboy | 0:e1ae1b9889a3 | 698 | { |
Reniboy | 0:e1ae1b9889a3 | 699 | lcd.clear(); |
Reniboy | 0:e1ae1b9889a3 | 700 | lcd.printString("SELECT A MODE:",0,0.5); |
Reniboy | 0:e1ae1b9889a3 | 701 | lcd.printString("CLASSIC (cm)", 11,2); |
Reniboy | 0:e1ae1b9889a3 | 702 | lcd.printString("RADAR MODE",11,3); |
Reniboy | 0:e1ae1b9889a3 | 703 | lcd.printString("CLASSIC (in)",11,4); |
Reniboy | 0:e1ae1b9889a3 | 704 | lcd.drawCircle(3,26.5,3,1); |
Reniboy | 0:e1ae1b9889a3 | 705 | lcd.refresh(); |
Reniboy | 0:e1ae1b9889a3 | 706 | } |
Reniboy | 0:e1ae1b9889a3 | 707 | |
Reniboy | 0:e1ae1b9889a3 | 708 | void classicMode1() |
Reniboy | 0:e1ae1b9889a3 | 709 | { |
Reniboy | 1:775f6e8071a2 | 710 | lcd.clear(); |
Reniboy | 1:775f6e8071a2 | 711 | lcd.printString("SELECT A MODE:",0,0.5); |
Reniboy | 2:31c5c3b46742 | 712 | lcd.printString("CLASSIC (cm)", 11,2); |
Reniboy | 1:775f6e8071a2 | 713 | lcd.printString("RADAR MODE",11,3); |
Reniboy | 2:31c5c3b46742 | 714 | lcd.printString("CLASSIC (in)",11,4); |
Reniboy | 1:775f6e8071a2 | 715 | lcd.drawCircle(3,34.5,3,1); |
Reniboy | 1:775f6e8071a2 | 716 | lcd.refresh(); |
Reniboy | 1:775f6e8071a2 | 717 | } |
Reniboy | 0:e1ae1b9889a3 | 718 | |
Reniboy | 0:e1ae1b9889a3 | 719 | |
Reniboy | 1:775f6e8071a2 | 720 | void sw2_isr() |
Reniboy | 0:e1ae1b9889a3 | 721 | { |
Reniboy | 1:775f6e8071a2 | 722 | g_sw2_flag = 1; // set flag in ISR |
Reniboy | 0:e1ae1b9889a3 | 723 | } |
Reniboy | 0:e1ae1b9889a3 | 724 | void sw3_isr() |
Reniboy | 0:e1ae1b9889a3 | 725 | { |
Reniboy | 0:e1ae1b9889a3 | 726 | g_sw3_flag = 1; |
Reniboy | 0:e1ae1b9889a3 | 727 | } |
Reniboy | 0:e1ae1b9889a3 | 728 | |
Reniboy | 0:e1ae1b9889a3 | 729 | |
Reniboy | 0:e1ae1b9889a3 | 730 | |
Reniboy | 0:e1ae1b9889a3 | 731 | void timer_isr() |
Reniboy | 0:e1ae1b9889a3 | 732 | { |
Reniboy | 0:e1ae1b9889a3 | 733 | g_timer_flag = 1; /** @Brief Set flag in ISR **/ |
Reniboy | 0:e1ae1b9889a3 | 734 | } |