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

Dependencies:   microbit

Revision:
6:e316416cae08
Parent:
1:17905d919813
--- a/LedMatrix.cpp	Mon Feb 20 09:33:31 2017 +0000
+++ b/LedMatrix.cpp	Thu Feb 23 15:25:48 2017 +0000
@@ -2,7 +2,6 @@
 
 LedMatrix::LedMatrix()
 {
-    //ledMatrix = vector<vector<int> >(5, vector<int>(5, 0));
     for (int i = 0; i < 5; ++i)
     {
         vector<int> temp;
@@ -15,14 +14,6 @@
     }
 }
 
-/*void LedMatrix::setLedMatrix(ManagedString data)
-{
-    int row, col;
-    row = (int)data.charAt(0);
-    col = (int)data.charAt(1);
-    ledMatrix[row][col] == 0 ? ledMatrix[row][col] = 1 : ledMatrix[row][col] = 0;
-}*/
-
 void LedMatrix::setLedMatrix(int row, int col)
 {
     ledMatrix[row][col] = ledMatrix[row][col] == 0 ? 1 : 0;
@@ -30,7 +21,7 @@
 
 MicroBitImage LedMatrix::getMatrixImage()
 {
-    char* ledStatus;
+    char* ledStatus = new char[50];
     
     for (int i = 0; i < 5; ++i)
     {
@@ -38,14 +29,18 @@
         {
             if (j != 4)
             {
-                ledStatus = ledStatus + (ledMatrix[i][j] == 0 ? '0': '1') + ',';
+            ledStatus[i*10 + j*2] = (ledMatrix[i][j] == 0 ? '0' : '1');
+            ledStatus[i*10 + j*2 + 1] = ',';
             }
             else
             {
-                ledStatus = ledStatus + (ledMatrix[i][j] == 0 ? '0': '1') + '\n';
+            ledStatus[i*10 + j*2] = (ledMatrix[i][j] == 0 ? '0' : '1');
+            ledStatus[i*10 + j*2 + 1] = '\n';
             }
         }
     }
     MicroBitImage matrixImage(ledStatus);
+    delete ledStatus;
+    ledStatus = NULL;
     return matrixImage;
 }
\ No newline at end of file