![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
TJPS
Fork of Laser_Rangefinder by
Diff: main.cpp
- Revision:
- 1:d576753ebd76
- Parent:
- 0:ccc26a94788d
diff -r ccc26a94788d -r d576753ebd76 main.cpp --- a/main.cpp Sun Nov 06 02:08:57 2011 +0000 +++ b/main.cpp Mon Feb 24 22:51:57 2014 +0000 @@ -1,50 +1,28 @@ #include "mbed.h" -//Demo program for the Parallax Laser Range Finder -// -DigitalOut myled(LED1); +#include "string.h" +#include "LRF.h" + Serial pc(USBTX, USBRX); -Serial lrf(p9,p10); +extern DigitalOut myled; +extern Serial lrf; + +#define TRIANGLE 3 +#define RECTANGLE 2 +#define CIRCLE 1 int main() { - int mm_range=0; - char lrfchar=0; - -//Print prompt - pc.printf("\f\nLaser Range Finder demo program\n\r"); -//Delay for lrf power on startup - wait(2.5); - lrf.baud(115200); + int shape; + + LRFinit(); + shape=GetShape(); + pc.printf("Shape:\n"); + + if(shape == TRIANGLE) pc.printf("Triangle\n"); + else if(shape == RECTANGLE) pc.printf("Rectangle\n"); + else pc.printf("Circle\n"); + -// lrf autobaud setup - do { - lrf.putc('U'); - pc.putc('.'); - wait(.2); - if (lrf.readable()) lrfchar = lrf.getc(); - } while (lrfchar != ':'); - pc.printf("\n\r"); - // clear out any extra characters - just in case - while (lrf.readable()) { - lrfchar = lrf.getc(); + } -// Loop taking range readings forever - while (1) { - myled=1; - lrf.putc('B'); //Take Binary range reading - // read in the four bytes for the range in mm (MSB first) - mm_range=0; - mm_range=lrf.getc(); - mm_range=(mm_range<<8)|lrf.getc(); - mm_range=(mm_range<<8)|lrf.getc(); - mm_range=(mm_range<<8)|lrf.getc(); - myled=0; - //eat CR & ":" command prompt - do { - lrfchar=lrf.getc(); - } while (lrfchar != ':'); - //Display readings on PC Virtual Com port via USB cable - pc.printf("Range is %d mm\n\r",mm_range); - } -}