Program to read LIDAR values using I2C and send UART messages using UART 2 & UART 3

Dependencies:   mbed LidarLitev2

Revision:
1:89b49ebbe3db
Parent:
0:ee825cd264b6
--- a/main.cpp	Mon Mar 26 23:51:52 2018 +0000
+++ b/main.cpp	Thu Mar 28 02:54:00 2019 +0000
@@ -2,8 +2,11 @@
 
 
 LidarLitev2 Lidar(PTE25, PTE24);
-Serial pc(USBTX,USBRX);
-Serial device(PTC17, NC);
+Serial pc(USBTX,USBRX);             //UART0
+Serial device(PTC17, PTC16);           //UART3
+Serial kw41z(PTD3, PTD2);                     //UART2
+
+int counter = 0;
 
 Timer dt;
 
@@ -12,6 +15,7 @@
     
     pc.baud(115200);
     device.baud(115200);
+    kw41z.baud(115200);
     Lidar.configure();
     dt.start();
 
@@ -23,56 +27,65 @@
           //pc.printf("%d\n",temp);
          
          dt.reset();
-         if(Lidar.distance()>1 and Lidar.distance()<=30)
+         if(Lidar.distance()>1 and Lidar.distance()<=15)
          {
          device.printf("1"); 
-         pc.printf("case: 1\r\n");   
+         //kw41z.printf("coap CON POST fd18:16b7:2982:2c23:d07c:a5c0:a751:5e10 /led rgb r255 g0 b0\n");
+         pc.printf("case: 1\r\n"); 
+         if (counter == 0){
+         kw41z.printf("coap CON POST fd18:16b7:2982:2c23:d07c:a5c0:a751:5e10 /led rgb r255 g0 b0\n"); 
+        counter = 1;
+           }    
         }
         
-        else if(Lidar.distance()>30 and Lidar.distance()<=60)
+        else if(Lidar.distance()>15 and Lidar.distance()<=60)
         {
-         device.printf("2");  
-           pc.printf("case: 2\r\n");  
+         device.printf("2"); 
+         pc.printf("case: 2\r\n");
+         if (counter == 0){
+         kw41z.printf("coap CON POST fd18:16b7:2982:2c23:d07c:a5c0:a751:5e10 /led rgb r255 g0 b0\n"); 
+        counter = 1;
+           }  
          }
-                 else if(Lidar.distance()>60 and Lidar.distance()<=90)
+                 else if(Lidar.distance()>60 and Lidar.distance()<=120)
         {
          device.printf("3");  
-           pc.printf("case: 3\r\n");  
+         //kw41z.printf("coap CON POST fd18:16b7:2982:2c23:d07c:a5c0:a751:5e10 /led rgb r0 g255 b0\n");
+           pc.printf("case: 3\r\n"); 
+           if (counter == 1) {
+               kw41z.printf("coap CON POST fd18:16b7:2982:2c23:d07c:a5c0:a751:5e10 /led rgb r0 g255 b0\n");
+               counter = 0;
+               }
          }
-                 else if(Lidar.distance()>90 and Lidar.distance()<=120)
+                 else if(Lidar.distance()>120 and Lidar.distance()<=180)
         {
-         device.printf("4"); 
-           pc.printf("case: 4\r\n");   
+         device.printf("4");
+         //kw41z.printf("coap CON POST fd18:16b7:2982:2c23:d07c:a5c0:a751:5e10 /led rgb r0 g255 b0\n"); 
+           pc.printf("case: 4\r\n");  
+            if (counter == 1) {
+               kw41z.printf("coap CON POST fd18:16b7:2982:2c23:d07c:a5c0:a751:5e10 /led rgb r0 g255 b0\n");
+               counter = 0;
+               } 
          }
-                 else if(Lidar.distance()>120 and Lidar.distance()<=150)
+                 else if(Lidar.distance()>180)
         {
          device.printf("5");
-           pc.printf("case: 5\r\n");    
-         }
-                 else if(Lidar.distance()>150 and Lidar.distance()<=180)
-        {
-         device.printf("6"); 
-           pc.printf("case: 6\r\n");   
-         }
-                 else if(Lidar.distance()>180 and Lidar.distance()<=210)
-        {
-         device.printf("7");
-           pc.printf("case: 7\r\n");    
-         }
-                 else if(Lidar.distance()>210 and Lidar.distance()<=240)
-        {
-         device.printf("8");  
-           pc.printf("case: 8\r\n");  
-         }
-                 else if(Lidar.distance()>240 and Lidar.distance()<=800)
-        {
-         device.printf("9"); 
-           pc.printf("case: 9\r\n");   
+         //kw41z.printf("coap CON POST fd18:16b7:2982:2c23:d07c:a5c0:a751:5e10 /led rgb r0 g255 b0\n");
+           pc.printf("case: 5\r\n"); 
+            if (counter == 1) {
+               kw41z.printf("coap CON POST fd18:16b7:2982:2c23:d07c:a5c0:a751:5e10 /led rgb r0 g255 b0\n");
+               counter = 0;
+               }   
          }
          else
          {
              device.printf("0");
-               pc.printf("case: 0\r\n");  
+             //kw41z.printf("coap CON POST fd18:16b7:2982:2c23:d07c:a5c0:a751:5e10 /led rgb r0 g255 b0\n");
+               pc.printf("case: 0\r\n"); 
+                if (counter == 0) {
+               kw41z.printf("coap CON POST fd18:16b7:2982:2c23:d07c:a5c0:a751:5e10 /led rgb r255 g0 b0\n");
+               counter = 1;
+               } 
              }
          
 }