Final revision to radar/distance measuring tool. Radar feature not implemented within time frame due to issues with hardware and mbed.org servers
Dependencies: N5110 PowerControl SRF02 mbed
Revision 1:d374bd09fa94, committed 2015-05-11
- Comitter:
- el13k3s
- Date:
- Mon May 11 17:03:00 2015 +0000
- Parent:
- 0:ca83aafb7dcb
- Commit message:
- Final code for radar/distance measuring tool.; Radar feature - unable to implement within time frame due to issues with hardware and mbed.org server
Changed in this revision
diff -r ca83aafb7dcb -r d374bd09fa94 N5110.lib --- a/N5110.lib Mon May 11 16:35:26 2015 +0000 +++ b/N5110.lib Mon May 11 17:03:00 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/eencae/code/N5110/#505f281a04fa +http://developer.mbed.org/users/el13k3s/code/N5110/#505f281a04fa
diff -r ca83aafb7dcb -r d374bd09fa94 SRF02.lib --- a/SRF02.lib Mon May 11 16:35:26 2015 +0000 +++ b/SRF02.lib Mon May 11 17:03:00 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/eencae/code/SRF02/#98253d9cbccd +http://developer.mbed.org/users/el13k3s/code/SRF02/#98253d9cbccd
diff -r ca83aafb7dcb -r d374bd09fa94 main.cpp --- a/main.cpp Mon May 11 16:35:26 2015 +0000 +++ b/main.cpp Mon May 11 17:03:00 2015 +0000 @@ -169,11 +169,12 @@ unitSW.mode(PullUp); unitSW.rise(&units); - /// switch to radar display - not + /* + /// switch to radar display radarDist.rise(&radar); - /// switch to distance reader in cm radarDist.fall(¢imetre); + */ /// Device welcome messages - print strings of characters at defined coordinates lcd.printString("Radar/Distance",0,1); @@ -230,10 +231,13 @@ /// function to indicate object proximity on LED and buzzer in CM +/// Buzzer counts down to sensor update +/// LED and buzzer indicate when proximity is < 50 cm void proximityCm() { int distance = sensor.getDistanceCm(); + /// beep at max volume (dutycycle = 50%) for 3 sec if (distance < 50) { led = 1; buzzer = 0.5; @@ -261,7 +265,7 @@ wait(0.25); lcd.refresh(); } - + /// quieter buzzer countdown to next update else { buzzer = 1; wait(0.5); @@ -283,10 +287,13 @@ /// function to indicate object proximity on LED and buzzer in INCHES +/// Buzzer counts down to sensor update +/// LED and buzzer indicate when proximity is < 20 inches (~ 50 cm) void proximityIn() { int distance = sensor.getDistanceInch(); + /// beep at max volume (dutycycle = 50%) for 3 sec if (distance < 20) { led = 1; buzzer = 0.5; @@ -314,6 +321,7 @@ wait(0.25); lcd.refresh(); } + /// quieter buzzer countdown to next update else { buzzer = 1; wait(0.5); @@ -327,7 +335,7 @@ wait(0.5); buzzer = 1; wait(0.5); - lcd.refresh(); + /// clear screen and buffer lcd.clear(); } @@ -339,12 +347,14 @@ void initMeasureIn() { if (unit == 0) { - leds = 8; // switch LED4 on to indicate unit + /// switch LED4 on to indicate unit + leds = 8; centimetre(); } if (unit == 1) { - leds = 2; // switch LED2 on to indicate unit + /// switch LED2 on to indicate unit + leds = 2; inches(); } @@ -356,12 +366,10 @@ void initDisplay() { if (pixel == 0) { - leds = 4; // switch LED3 on to indicate display mode normal(); } if (pixel == 1) { - leds = 1; // switch LED1 on to indicate display mode invert(); } @@ -394,6 +402,7 @@ void centimetre() { int distance = sensor.getDistanceCm(); + /// Print the formatted output from the sensor int length = sprintf(buffer,"D = %d cm",distance); /// Only allow data with length < or = 24 to be displayed @@ -411,7 +420,7 @@ void inches() { int distance = sensor.getDistanceInch(); - + /// Print the formatted output from the sensor int length = sprintf(buffer,"D = %d inches",distance); if (length<= 14) @@ -424,161 +433,160 @@ -/// function for radar display - not called because it returns an error on the mbed +/// function for radar display - not called because distance reading feature takes precedence in while loop +/// Attempt at using a switch statement unsuccessful void radar() { lcd.clear(); int distance = sensor.getDistanceCm(); - // loop through + /// Assume max detectable distance is 240 cm. + /// Dividing by 48 pixels across screen gives 5cm for every pixel. + /// Set each pixel along the centre of the screen (x = 42) to 1 + /// for distance increases by 5 cm. + /// Set any distance above 230cm to final pixel (41,48). if (distance < 5) { - lcd.setPixel(41,1); + lcd.setPixel(42,1); } else if (distance < 10) { - lcd.setPixel(41,2); + lcd.setPixel(42,2); } else if (distance < 15) { - lcd.setPixel(41,3); + lcd.setPixel(42,3); } else if (distance < 20) { - lcd.setPixel(41,4); + lcd.setPixel(42,4); } else if (distance < 25) { - lcd.setPixel(41,5); + lcd.setPixel(42,5); } else if (distance < 30) { - lcd.setPixel(41,6); + lcd.setPixel(42,6); } else if (distance < 35) { - lcd.setPixel(41,7); + lcd.setPixel(42,7); } else if (distance < 40) { - lcd.setPixel(41,8); + lcd.setPixel(42,8); } else if (distance < 45) { - lcd.setPixel(41,9); + lcd.setPixel(42,9); } else if (distance < 50) { - lcd.setPixel(41,10); + lcd.setPixel(42,10); } else if (distance < 55) { - lcd.setPixel(41,11); + lcd.setPixel(42,11); } else if (distance < 60) { - lcd.setPixel(41,12); + lcd.setPixel(42,12); } else if (distance < 65) { - lcd.setPixel(41,13); + lcd.setPixel(42,13); } else if (distance < 70) { - lcd.setPixel(41,14); + lcd.setPixel(42,14); } else if (distance < 75) { - lcd.setPixel(41,15); + lcd.setPixel(42,15); } else if (distance < 80) { - lcd.setPixel(41,16); + lcd.setPixel(42,16); } else if (distance < 85) { - lcd.setPixel(41,17); + lcd.setPixel(42,17); } else if (distance < 90) { - lcd.setPixel(41,18); + lcd.setPixel(42,18); } else if (distance < 95) { - lcd.setPixel(41,19); + lcd.setPixel(42,19); } else if (distance < 100) { - lcd.setPixel(41,20); + lcd.setPixel(42,20); } else if (distance < 105) { - lcd.setPixel(41,21); + lcd.setPixel(42,21); } else if (distance < 110) { - lcd.setPixel(41,22); + lcd.setPixel(42,22); } else if (distance < 115) { - lcd.setPixel(41,23); + lcd.setPixel(42,23); } else if (distance < 120) { - lcd.setPixel(41,24); + lcd.setPixel(42,24); } else if (distance < 125) { - lcd.setPixel(41,25); + lcd.setPixel(42,25); } else if (distance < 130) { - lcd.setPixel(41,26); + lcd.setPixel(42,26); } else if (distance < 135) { - lcd.setPixel(41,27); + lcd.setPixel(42,27); } else if (distance < 140) { - lcd.setPixel(41,28); + lcd.setPixel(42,28); } else if (distance < 145) { - lcd.setPixel(41,29); + lcd.setPixel(42,29); } else if (distance < 150) { - lcd.setPixel(41,30); + lcd.setPixel(42,30); } else if (distance < 155) { - lcd.setPixel(41,31); + lcd.setPixel(42,31); } else if (distance < 160) { - lcd.setPixel(41,32); + lcd.setPixel(42,32); } else if (distance < 165) { - lcd.setPixel(41,33); + lcd.setPixel(42,33); } else if (distance < 170) { - lcd.setPixel(41,34); + lcd.setPixel(42,34); } else if (distance < 175) { - lcd.setPixel(41,35); + lcd.setPixel(42,35); } else if (distance < 180) { - lcd.setPixel(41,36); + lcd.setPixel(42,36); } else if (distance < 185) { - lcd.setPixel(41,37); + lcd.setPixel(42,37); } else if (distance < 190) { - lcd.setPixel(41,38); + lcd.setPixel(42,38); } else if (distance < 195) { - lcd.setPixel(41,39); + lcd.setPixel(42,39); } else if (distance < 200) { - lcd.setPixel(41,40); + lcd.setPixel(42,40); } else if (distance < 205) { - lcd.setPixel(41,41); + lcd.setPixel(42,41); } else if (distance < 210) { - lcd.setPixel(41,42); + lcd.setPixel(42,42); } else if (distance < 215) { - lcd.setPixel(41,43); + lcd.setPixel(42,43); } else if (distance < 220) { - lcd.setPixel(41,44); + lcd.setPixel(42,44); } else if (distance < 225) { - lcd.setPixel(41,45); + lcd.setPixel(42,45); } else if (distance < 230) { - lcd.setPixel(41,46); - } - else if (distance < 235) { - lcd.setPixel(41,47); - } - else if (distance < 240) { - lcd.setPixel(41,48); + lcd.setPixel(42,46); } else { - lcd.setPixel(41,48); + lcd.setPixel(42,47); } wait(3); - lcd.refresh(); + lcd.refresh(); }