Sends compass and accelerometer data, receives data and displays on LED matrix

Dependencies:   microbit

Files at this revision

API Documentation at this revision

Comitter:
kinga
Date:
Fri Feb 24 13:16:04 2017 +0000
Parent:
7:e3d1f064894b
Commit message:
little refactor: working

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e3d1f064894b -r c0e98b2fc93a main.cpp
--- a/main.cpp	Thu Feb 23 15:37:20 2017 +0000
+++ b/main.cpp	Fri Feb 24 13:16:04 2017 +0000
@@ -43,15 +43,11 @@
     serial.send(getMessage(), ASYNC);
 }  
 
-void switchLedMatrix(LedMatrix matrix)
+void switchLedMatrix(ManagedString buffer, LedMatrix& myLedMatrix)
 {
-    ManagedString buffer = readData();
     int offsetToGetInt = 48;
-    if (buffer.length() != 0)
-    {
-        matrix.setLedMatrix((int)buffer.charAt(0) - offsetToGetInt, (int)buffer.charAt(1) - offsetToGetInt);
-        uBit.display.print(matrix.getMatrixImage());
-    }
+    myLedMatrix.setLedMatrix((int)buffer.charAt(0) - offsetToGetInt, (int)buffer.charAt(1) - offsetToGetInt);
+    uBit.display.print(myLedMatrix.getMatrixImage());
 }
 
 
@@ -61,7 +57,11 @@
     LedMatrix myLedMatrix;
     while(1)
     {   
-        switchLedMatrix(myLedMatrix);
+        ManagedString buffer = readData();
+        if (buffer.length() != 0)
+        {
+            switchLedMatrix(buffer, myLedMatrix);
+        }
         sendData();
         uBit.sleep(500);
     }