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