Garn E
/
HC-SR04
.
Fork of HC-SR04 by
Revision 6:4f947daf86c8, committed 2016-12-04
- Comitter:
- Viktor5
- Date:
- Sun Dec 04 15:11:07 2016 +0000
- Parent:
- 5:889566fb3a85
- Commit message:
- .
Changed in this revision
AutomationElements.lib | Show diff for this revision Revisions of this file |
main.cpp | Show diff for this revision Revisions of this file |
diff -r 889566fb3a85 -r 4f947daf86c8 AutomationElements.lib --- a/AutomationElements.lib Mon Dec 07 11:45:44 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/teams/TVZ-Mechatronics-Team/code/AutomationElements/#b9e11da0f2eb
diff -r 889566fb3a85 -r 4f947daf86c8 main.cpp --- a/main.cpp Mon Dec 07 11:45:44 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -#include "mbed.h" -#include "HCSR04.h" -#include "AutomationElements.h" - -Serial pc(USBTX, USBRX); -HCSR04 sensor(p5, p7); -float sampleTime = 0.1; -PT1 filter(1, 2, sampleTime); // filter with a time constant of 2 seconds -float distance = 0; -float filteredDistance = 0; -Timer timer; - -int main() { - sensor.setRanges(4, 400); - pc.printf("Minimum sensor range = %g cm\n\rMaximum sensor range = %g cm\n\r", sensor.getMinRange(), sensor.getMaxRange()); - pc.printf("Sensor: Filtered:\n\r"); - - timer.start(); - distance = sensor.getDistance_mm(); - timer.stop(); - int time1 = timer.read_us(); - pc.printf("Time to get distance: %d us \n\r", time1); - timer.reset(); - - timer.start(); - filter.in(distance); - filteredDistance = filter.out(); - timer.stop(); - int time2 = timer.read_us(); - pc.printf("Time to filter result: %d us \n\r", time2); - timer.reset(); - - timer.start(); - pc.printf("%7.1f mm %7.1f mm \r", distance, filteredDistance); - timer.stop(); - int time3 = timer.read_us(); - pc.printf("Time to printf one line: %d us \n\r", time3); - timer.reset(); - - pc.printf("Sensor: Filtered:\n\r"); - - while(1) { - distance = sensor.getDistance_mm(); - filter.in(distance); - filteredDistance = filter.out(); - pc.printf("%7.1f mm %7.1f mm \r", distance, filteredDistance); - wait_us(sampleTime*1e6 - time1 - time2 - time3); - } -} \ No newline at end of file