squix78 / MAX7219LedMatrix

Library for the ESP8266 on Arduino IDE displaying text on multiple 8x8 led matrices
MIT License
159 stars 71 forks source link

Rotate 90 degree? #7

Open ozett opened 8 years ago

ozett commented 8 years ago

Your lib does not Support a Rotation of certain degree? Or is it in the lib? How to Set? Thanks for help.. +1 (Or are you expanding your Code?)

dotsam commented 8 years ago

This python library (https://github.com/rm-hull/max7219) supports the "vertical" configuration needed to work with modules like this one http://www.gearbest.com/raspberry-pi/pp_391811.html

I'm going to take a look to see if I can incorporate this functionality in this library. I'll submit a PR if I get it working.

adityarao commented 7 years ago

I have fixed by changing the commit() api as below :

void LedMatrix::commit() {
    byte index = B0000001;
    byte col; 

    if(deviceOrientation == HORIZONTAL) {
        for (col = 0; col < myNumberOfDevices * 8; col++) {
            sendByte(col / 8, col % 8 + 1, cols[col]); 
        }
    } else if(deviceOrientation == VERTICAL){ // orient the device vertically
        for (col = 0; col < myNumberOfDevices * 8; col++) {
            xcols[col] = 0; 
        }
        // little inefficient, can be enhanced, rotate the matrix !
        for (col = 0; col < myNumberOfDevices * 8; col++) {

            for(byte bits = 0; bits < 8; bits++) 
              xcols[col] |= ((cols[bits + 8*(col/8)] & (index << (col%8))) ?
                                     (B10000000 >> bits) : 0);  
            sendByte(col / 8, col % 8 + 1, xcols[col]);
        }
    }
}
adityarao commented 7 years ago

img_20170918_202009

See the image on a 1x4 matrix module

TLR1000 commented 6 years ago

Look for deviceOrientation in the .h