2019年8月2日 星期五

使用 MAX7219 驅動4個 8x8 矩陣式LED 顯示器



之前買了三個 6cm x 6cm 的MAX7219 白光LED點矩陣,把三個點矩陣串接起來並使用MaxMatrix Library做NTP時鐘,顯示都正常,所以就再加碼,買了比較小一點 4 in 1的,打算放在臥室



就在收到貨後,立馬更換,點亮了~,不過字體怎麼怪怪的,轉了90度,Google了一下,發現有MD_MAX72XX library 可以做轉向顯示,但是我已經用MaxMatrix 寫好code,不想大改了,所以只好捲起袖子,開始 trace MaxMatrix的code,看看能不能在最小幅度的修改下,達到文字旋轉90度的需求



下面是修改MaxMatrix.c,轉90度顯示所做的修改,有三個副程式需做修改

void MaxMatrix::setColumn(byte col, byte value)
{
    int xx = (col%8);   
    int yy = 0 ;   
   
    for (int row_i=0;row_i<8;row_i++){
        yy = (col/8)*8+row_i;
        setDot(xx, yy, bitRead(value, row_i));
    }
}

void MaxMatrix::setDot(byte col, byte row, byte value)
{
    int yy = 7-(col%8);
    int xx = (col/8)*8+row;
   
    bitWrite(buffer[xx], yy, value);
   
    int n = xx / 8;
    int c = (xx % 8);
    digitalWrite(load, LOW);
    for (int i=0; i<num; i++)
    {
        if (i == n)
        {
            shiftOut(data, clock, MSBFIRST, c + 1);
            shiftOut(data, clock, MSBFIRST, buffer[xx]);
        }
        else
        {
            shiftOut(data, clock, MSBFIRST, 0);
            shiftOut(data, clock, MSBFIRST, 0);
        }
    }
	digitalWrite(load, LOW);
	digitalWrite(load, HIGH);
}

void MaxMatrix::writeSprite(int x, int y, const byte* sprite)
{
	int w = sprite[0];
	int h = sprite[1];
	   
    for (int i=0; i<w; i++){
            for (int j=0; j<h; j++)
            {
                int c = x + i;
                int r = y + j;
                if (c>=0 && c<80 && r>=0 && r<8)
                    setDot(c, r, bitRead(sprite[i+2], j));
            }
    }
}


修改完結果如下,可正常顯示,但Scroll 移動的部分就沒有修改,所以若要捲動的話顯示會出問題的,這部份等有空再來改了






Free ERP on the Raspberry Pi (odoo)

  #更新系統軟體 sudo apt update && sudo apt upgrade -y #安裝資料庫 sudo apt install postgresql -y #安裝py程序 sudo apt install python3-pip -y #安裝od...