マトリックスLED

ピン配置(MNA20SR092G)

参考サイト

IchigoLED64

ピン配置

図は文字が書かれている面を下とする
C1~C8は列でアノード(+)
R1~R8は行でカソード(-)

LPC1444との結線

LPC1444との結線

完成例

マトリックスLED

プログラム(DigitalOut)

#include "mbed.h"

Ticker timer;

DigitalOut col[] = {dp6,dp1,dp2,dp11,dp28,dp10,dp4,dp13};
DigitalOut row[] = {dp14,dp5,dp17,dp9,dp26,dp18,dp25,dp27};

uint8_t data[8][8] =   {
    {  0,  0,  0,  0,  0,  0,  0,  0 },
    {  0,  0,  0,  0,  0,  0,  0,  0 },
    {  0,  0,  1,  0,  0,  1,  0,  0 },
    {  0,  1,  1,  1,  1,  1,  1,  0 },
    {  0,  1,  1,  1,  1,  1,  1,  0 },
    {  0,  0,  1,  1,  1,  1,  0,  0 },
    {  0,  0,  0,  1,  1,  0,  0,  0 },
    {  0,  0,  0,  0,  0,  0,  0,  0 } 
};

int count = 0;

void attime(){
     count++;
}

int main() {
    //初期化
    for (int i = 0; i < 8; i++){
        col[i] = 0;
        row[i] = 1;
    }
    
    timer.attach(&attime,0.5);
    
    while(1) {
        int shift = count % 8;
        for (int i = 0; i < 8; i++)
        {
            row[i] = 0;
            for (int j = 0; j < 8; j++)
                col[j] = (int)data[i][(j + shift) % 8];
            row[i] = 1;
            for (int j = 0; j < 8; j++)
                col[j] = 0;
        }
    }
}

プログラム(BusOut)

#include "mbed.h"

Ticker timer;

BusOut col(dp6,dp1,dp2,dp11,dp28,dp10,dp4,dp13);
BusOut row(dp14,dp5,dp17,dp9,dp26,dp18,dp25,dp27);

uint8_t data[8] =   {
    0b00000000,
    0b00100100,
    0b00111100,
    0b01111110,
    0b01011010,
    0b01111110,
    0b00111100,
    0b00000000
};

int count = 0;

void attime(){
     count++;
}

int main() {
    // タイマ設定    
    timer.attach(&attime,0.5);
    
    while(1) {
        int shift = count % 8;
        int dir = (count / 16) % 2;
        for (int i = 0; i < 8; i++)
        {
            // 初期化
            col = 0b00000000;
            row = 0b11111111;
            // 表示
            row = ~(1 << i);
            if (dir == 0)
                col = data[(i + shift) % 8];    // 縦スクロール
            else
                col = data[i] << (8 - shift) | data[i] >> shift; // 横スクロール
        }
    }
}