Dev Joshi
/
SRF02_libv2
Library for the SRF02 ultrasonic rangefinder
main.cpp@0:862f11d627f9, 2011-07-10 (annotated)
- Committer:
- go2dev
- Date:
- Sun Jul 10 16:40:35 2011 +0000
- Revision:
- 0:862f11d627f9
v2 of this library, condenses the code base as discussed in this thread: http://mbed.org/forum/helloworld/topic/2234/
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
go2dev | 0:862f11d627f9 | 1 | //Useage example for the SRF02 Library |
go2dev | 0:862f11d627f9 | 2 | |
go2dev | 0:862f11d627f9 | 3 | #include "mbed.h" |
go2dev | 0:862f11d627f9 | 4 | #include "SRF02.h" |
go2dev | 0:862f11d627f9 | 5 | |
go2dev | 0:862f11d627f9 | 6 | |
go2dev | 0:862f11d627f9 | 7 | Serial debugport(USBTX,USBRX); |
go2dev | 0:862f11d627f9 | 8 | SRF02 mySensor(p9,p10,0xE0); |
go2dev | 0:862f11d627f9 | 9 | |
go2dev | 0:862f11d627f9 | 10 | |
go2dev | 0:862f11d627f9 | 11 | |
go2dev | 0:862f11d627f9 | 12 | |
go2dev | 0:862f11d627f9 | 13 | main() { |
go2dev | 0:862f11d627f9 | 14 | |
go2dev | 0:862f11d627f9 | 15 | time_t seconds = time(NULL); //Internal RTC |
go2dev | 0:862f11d627f9 | 16 | debugport.baud(115200); //set the buadrate (default is 9600 if this command is not used) |
go2dev | 0:862f11d627f9 | 17 | debugport.format(8,Serial::None,1); //config the serial port (default is 8N1) |
go2dev | 0:862f11d627f9 | 18 | debugport.printf("Hello World! %d \r\n", seconds); //send a message out of the serial port to check all is well |
go2dev | 0:862f11d627f9 | 19 | //include a time stamp for reference (seconds since power up) |
go2dev | 0:862f11d627f9 | 20 | |
go2dev | 0:862f11d627f9 | 21 | |
go2dev | 0:862f11d627f9 | 22 | while (1) { |
go2dev | 0:862f11d627f9 | 23 | |
go2dev | 0:862f11d627f9 | 24 | |
go2dev | 0:862f11d627f9 | 25 | debugport.printf("current distance: %.2f cm. (v2) \r\n", mySensor.measurecm()); |
go2dev | 0:862f11d627f9 | 26 | debugport.printf("current distance: %.2f inches.\r\n", mySensor.measurein()); |
go2dev | 0:862f11d627f9 | 27 | debugport.printf("current flightime: %.2f microseconds.\r\n", mySensor.measureus()); |
go2dev | 0:862f11d627f9 | 28 | |
go2dev | 0:862f11d627f9 | 29 | } |
go2dev | 0:862f11d627f9 | 30 | } |