Sends compass and accelerometer data, receives data and displays on LED matrix
Revision 3:5567512e8de7, committed 2017-02-20
- Comitter:
- kinga
- Date:
- Mon Feb 20 15:26:27 2017 +0000
- Parent:
- 2:541a2fae2429
- Child:
- 4:7f5e478f945c
- Commit message:
- working!!!
Changed in this revision
LedMatrix.cpp | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/LedMatrix.cpp Mon Feb 20 09:33:31 2017 +0000 +++ b/LedMatrix.cpp Mon Feb 20 15:26:27 2017 +0000 @@ -30,7 +30,7 @@ MicroBitImage LedMatrix::getMatrixImage() { - char* ledStatus; + char* ledStatus = new char[50]; for (int i = 0; i < 5; ++i) { @@ -38,11 +38,13 @@ { 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'; } } }
--- a/main.cpp Mon Feb 20 09:33:31 2017 +0000 +++ b/main.cpp Mon Feb 20 15:26:27 2017 +0000 @@ -32,14 +32,14 @@ return getCompassHeading() + getAccelerometerVectors(); } -int readData() +ManagedString readData() { return serial.read(2, ASYNC); } -/*int convertData(int num); +/*int convertData() { - return atoi(readData()[num]); + return atoi(readData()); }*/ /*void readData() @@ -65,8 +65,12 @@ //buffer = readData(); //myLedMatrix.setLedMatrix(temp / 10, temp % 10); //int buffer = readData(); - myLedMatrix.setLedMatrix((readData() /10), (readData() % 10)); - uBit.display.print(myLedMatrix.getMatrixImage()); + ManagedString buffer = readData(); + if (buffer.length() != 0) + { + myLedMatrix.setLedMatrix((int)buffer.charAt(0) - 48, (int)buffer.charAt(1) - 48); + uBit.display.print(myLedMatrix.getMatrixImage()); + } //readData(); sendData(); uBit.sleep(500);