Bluetooth communication for flocking.

Dependencies:   mbed

Fork of BeautifulMemeProject by James Hilder

Revision:
21:e5ab8c56a769
Parent:
20:e08376c0b4ea
diff -r e08376c0b4ea -r e5ab8c56a769 PsiSwarm/serial.cpp
--- a/PsiSwarm/serial.cpp	Fri Jan 15 14:42:42 2016 +0000
+++ b/PsiSwarm/serial.cpp	Fri Jan 15 18:38:59 2016 +0000
@@ -43,14 +43,24 @@
     {
         if(length == 8)
         {        
-            // Convert 360 to 255 values!
             for(int i = 0; i < length; i++)
             {
-                flocking_headings[i] = message[i];
-//                debug("%d, ", message[i]);
+                // Convert single byte value into a beacon heading in the range +/-180 degrees
+                float beacon_heading = message[i];
+                float degrees_per_value = 256.0f / 360.0f;
+                
+                if(beacon_heading != 0)
+                    beacon_heading /= degrees_per_value;
+                
+                beacon_heading -= 180;
+                
+                flocking_headings[i] = beacon_heading;
+                
+                debug("%d, ", flocking_headings[i]);
+                //debug("%f, ", beacon_heading);
             }
             
-//            debug("\n");
+            debug("\n");
         }
     }
 }