Lidar_LiteGarmin

Dependencies:   mbed LidarLitev2

Committer:
agaikwad
Date:
Mon Mar 26 23:51:52 2018 +0000
Revision:
0:ee825cd264b6
Get Lidar Data through UART

Who changed what in which revision?

UserRevisionLine numberNew contents of line
agaikwad 0:ee825cd264b6 1 #include "LidarLitev2.h"
agaikwad 0:ee825cd264b6 2
agaikwad 0:ee825cd264b6 3
agaikwad 0:ee825cd264b6 4 LidarLitev2 Lidar(PTE25, PTE24);
agaikwad 0:ee825cd264b6 5 Serial pc(USBTX,USBRX);
agaikwad 0:ee825cd264b6 6 Serial device(PTC17, NC);
agaikwad 0:ee825cd264b6 7
agaikwad 0:ee825cd264b6 8 Timer dt;
agaikwad 0:ee825cd264b6 9
agaikwad 0:ee825cd264b6 10 int main()
agaikwad 0:ee825cd264b6 11 {
agaikwad 0:ee825cd264b6 12
agaikwad 0:ee825cd264b6 13 pc.baud(115200);
agaikwad 0:ee825cd264b6 14 device.baud(115200);
agaikwad 0:ee825cd264b6 15 Lidar.configure();
agaikwad 0:ee825cd264b6 16 dt.start();
agaikwad 0:ee825cd264b6 17
agaikwad 0:ee825cd264b6 18 while(1){
agaikwad 0:ee825cd264b6 19 pc.printf( "distance =%d cm\t",Lidar.distance());
agaikwad 0:ee825cd264b6 20 //device.printf( "%d" ,Lidar.distance());
agaikwad 0:ee825cd264b6 21 //int temp=Lidar.distance();
agaikwad 0:ee825cd264b6 22 wait_ms(500);
agaikwad 0:ee825cd264b6 23 //pc.printf("%d\n",temp);
agaikwad 0:ee825cd264b6 24
agaikwad 0:ee825cd264b6 25 dt.reset();
agaikwad 0:ee825cd264b6 26 if(Lidar.distance()>1 and Lidar.distance()<=30)
agaikwad 0:ee825cd264b6 27 {
agaikwad 0:ee825cd264b6 28 device.printf("1");
agaikwad 0:ee825cd264b6 29 pc.printf("case: 1\r\n");
agaikwad 0:ee825cd264b6 30 }
agaikwad 0:ee825cd264b6 31
agaikwad 0:ee825cd264b6 32 else if(Lidar.distance()>30 and Lidar.distance()<=60)
agaikwad 0:ee825cd264b6 33 {
agaikwad 0:ee825cd264b6 34 device.printf("2");
agaikwad 0:ee825cd264b6 35 pc.printf("case: 2\r\n");
agaikwad 0:ee825cd264b6 36 }
agaikwad 0:ee825cd264b6 37 else if(Lidar.distance()>60 and Lidar.distance()<=90)
agaikwad 0:ee825cd264b6 38 {
agaikwad 0:ee825cd264b6 39 device.printf("3");
agaikwad 0:ee825cd264b6 40 pc.printf("case: 3\r\n");
agaikwad 0:ee825cd264b6 41 }
agaikwad 0:ee825cd264b6 42 else if(Lidar.distance()>90 and Lidar.distance()<=120)
agaikwad 0:ee825cd264b6 43 {
agaikwad 0:ee825cd264b6 44 device.printf("4");
agaikwad 0:ee825cd264b6 45 pc.printf("case: 4\r\n");
agaikwad 0:ee825cd264b6 46 }
agaikwad 0:ee825cd264b6 47 else if(Lidar.distance()>120 and Lidar.distance()<=150)
agaikwad 0:ee825cd264b6 48 {
agaikwad 0:ee825cd264b6 49 device.printf("5");
agaikwad 0:ee825cd264b6 50 pc.printf("case: 5\r\n");
agaikwad 0:ee825cd264b6 51 }
agaikwad 0:ee825cd264b6 52 else if(Lidar.distance()>150 and Lidar.distance()<=180)
agaikwad 0:ee825cd264b6 53 {
agaikwad 0:ee825cd264b6 54 device.printf("6");
agaikwad 0:ee825cd264b6 55 pc.printf("case: 6\r\n");
agaikwad 0:ee825cd264b6 56 }
agaikwad 0:ee825cd264b6 57 else if(Lidar.distance()>180 and Lidar.distance()<=210)
agaikwad 0:ee825cd264b6 58 {
agaikwad 0:ee825cd264b6 59 device.printf("7");
agaikwad 0:ee825cd264b6 60 pc.printf("case: 7\r\n");
agaikwad 0:ee825cd264b6 61 }
agaikwad 0:ee825cd264b6 62 else if(Lidar.distance()>210 and Lidar.distance()<=240)
agaikwad 0:ee825cd264b6 63 {
agaikwad 0:ee825cd264b6 64 device.printf("8");
agaikwad 0:ee825cd264b6 65 pc.printf("case: 8\r\n");
agaikwad 0:ee825cd264b6 66 }
agaikwad 0:ee825cd264b6 67 else if(Lidar.distance()>240 and Lidar.distance()<=800)
agaikwad 0:ee825cd264b6 68 {
agaikwad 0:ee825cd264b6 69 device.printf("9");
agaikwad 0:ee825cd264b6 70 pc.printf("case: 9\r\n");
agaikwad 0:ee825cd264b6 71 }
agaikwad 0:ee825cd264b6 72 else
agaikwad 0:ee825cd264b6 73 {
agaikwad 0:ee825cd264b6 74 device.printf("0");
agaikwad 0:ee825cd264b6 75 pc.printf("case: 0\r\n");
agaikwad 0:ee825cd264b6 76 }
agaikwad 0:ee825cd264b6 77
agaikwad 0:ee825cd264b6 78 }
agaikwad 0:ee825cd264b6 79 }