Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function to rotate each 8x8 matrix 90° left #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions LedMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ LedMatrix::LedMatrix(byte numberOfDevices, byte slaveSelectPin) {
myNumberOfDevices = numberOfDevices;
mySlaveSelectPin = slaveSelectPin;
cols = new byte[numberOfDevices * 8];
rotatedCols = new byte[numberOfDevices * 8];
}

/**
Expand Down Expand Up @@ -92,11 +93,13 @@ void LedMatrix::calculateTextAlignmentOffset() {
void LedMatrix::clear() {
for (byte col = 0; col < myNumberOfDevices * 8; col++) {
cols[col] = 0;
}

}
}

void LedMatrix::commit() {
if ( rotationIsEnabled ) {
rotateLeft();
}
for (byte col = 0; col < myNumberOfDevices * 8; col++) {
sendByte(col / 8, col % 8 + 1, cols[col]);
}
Expand Down Expand Up @@ -163,4 +166,19 @@ void LedMatrix::setColumn(int column, byte value) {

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++) {
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);
}
8 changes: 8 additions & 0 deletions LedMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,15 @@ 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;
byte* rotatedCols;
byte spiregister[8];
byte spidata[8];
String myText;
Expand All @@ -130,6 +136,8 @@ class LedMatrix {
byte mySlaveSelectPin = 0;
byte myCharWidth = 7;
byte myTextAlignment = 1;
bool rotationIsEnabled = false;

void calculateTextAlignmentOffset();
void rotateLeft();
};