From 25974e09837f995c623e0180356a354d4366934c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=BChl?= Date: Mon, 17 Oct 2016 20:57:25 +0200 Subject: [PATCH 1/3] added function rotateLeft() can now rotate single 8x8 blocks --- LedMatrix.cpp | 17 +++++++++++++++-- LedMatrix.h | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/LedMatrix.cpp b/LedMatrix.cpp index 560339e..b9b787a 100644 --- a/LedMatrix.cpp +++ b/LedMatrix.cpp @@ -9,6 +9,7 @@ LedMatrix::LedMatrix(byte numberOfDevices, byte slaveSelectPin) { myNumberOfDevices = numberOfDevices; mySlaveSelectPin = slaveSelectPin; cols = new byte[numberOfDevices * 8]; + rotatedCols = new byte[numberOfDevices * 8]; } /** @@ -92,11 +93,12 @@ void LedMatrix::calculateTextAlignmentOffset() { void LedMatrix::clear() { for (byte col = 0; col < myNumberOfDevices * 8; col++) { cols[col] = 0; - } - + rotatedCols[col] = 0; + } } void LedMatrix::commit() { + rotateLeft(); for (byte col = 0; col < myNumberOfDevices * 8; col++) { sendByte(col / 8, col % 8 + 1, cols[col]); } @@ -163,4 +165,15 @@ void LedMatrix::setColumn(int column, byte value) { void LedMatrix::setPixel(byte x, byte y) { bitWrite(cols[x], y, true); +} + +void LedMatrix::rotateLeft() { + for (byte deviceNum = 0; deviceNum < myNumberOfDevices; deviceNum++) { + for(byte posY = 0; posY < 8; posY++) { + for(byte posX = 0; posX < 8; posX++) { + bitWrite(rotatedCols[8 * (deviceNum) + posY], posX, bitRead(cols[8 * (deviceNum) + 7-posX], posY)); + } + } + } + memcpy(cols, rotatedCols, myNumberOfDevices * 8); } \ No newline at end of file diff --git a/LedMatrix.h b/LedMatrix.h index d622e54..48be71a 100644 --- a/LedMatrix.h +++ b/LedMatrix.h @@ -119,6 +119,7 @@ class LedMatrix { private: byte* cols; + byte* rotatedCols; byte spiregister[8]; byte spidata[8]; String myText; @@ -132,4 +133,5 @@ class LedMatrix { byte myTextAlignment = 1; void calculateTextAlignmentOffset(); + void rotateLeft(); }; \ No newline at end of file From 23d9cd972e49054b168a1b924defea2a4e021dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=BChl?= Date: Mon, 17 Oct 2016 21:18:24 +0200 Subject: [PATCH 2/3] =?UTF-8?q?added=20function=20setRotation(true|false)?= =?UTF-8?q?=20to=20enable/disable=2090=C2=B0=20rotation=20for=20each=208x8?= =?UTF-8?q?=20matrix.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LedMatrix.cpp | 10 ++++++++-- LedMatrix.h | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/LedMatrix.cpp b/LedMatrix.cpp index b9b787a..7d03519 100644 --- a/LedMatrix.cpp +++ b/LedMatrix.cpp @@ -93,12 +93,14 @@ void LedMatrix::calculateTextAlignmentOffset() { void LedMatrix::clear() { for (byte col = 0; col < myNumberOfDevices * 8; col++) { cols[col] = 0; - rotatedCols[col] = 0; + //rotatedCols[col] = 0; } } void LedMatrix::commit() { - rotateLeft(); + if ( rotationIsEnabled ) { + rotateLeft(); + } for (byte col = 0; col < myNumberOfDevices * 8; col++) { sendByte(col / 8, col % 8 + 1, cols[col]); } @@ -167,6 +169,10 @@ void LedMatrix::setPixel(byte x, byte y) { bitWrite(cols[x], y, true); } +void LedMatrix::setRotation(bool enabled) { + rotationIsEnabled = enabled; +} + void LedMatrix::rotateLeft() { for (byte deviceNum = 0; deviceNum < myNumberOfDevices; deviceNum++) { for(byte posY = 0; posY < 8; posY++) { diff --git a/LedMatrix.h b/LedMatrix.h index 48be71a..ee5e01d 100644 --- a/LedMatrix.h +++ b/LedMatrix.h @@ -116,6 +116,11 @@ class LedMatrix { * Oscilate the text between the two limits. */ void oscillateText(); + + /** + * Enables 90° rotation for each 8x8 matrix. + */ + void setRotation(bool enabled); private: byte* cols; @@ -131,6 +136,7 @@ class LedMatrix { byte mySlaveSelectPin = 0; byte myCharWidth = 7; byte myTextAlignment = 1; + bool rotationIsEnabled = false; void calculateTextAlignmentOffset(); void rotateLeft(); From 37e6adf210963815df66493dc7c887922733342b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=BChl?= Date: Mon, 17 Oct 2016 21:20:42 +0200 Subject: [PATCH 3/3] removed comment --- LedMatrix.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/LedMatrix.cpp b/LedMatrix.cpp index 7d03519..936f3d0 100644 --- a/LedMatrix.cpp +++ b/LedMatrix.cpp @@ -93,7 +93,6 @@ void LedMatrix::calculateTextAlignmentOffset() { void LedMatrix::clear() { for (byte col = 0; col < myNumberOfDevices * 8; col++) { cols[col] = 0; - //rotatedCols[col] = 0; } }