見出し画像

8×8ドットマトリックス4連(2)

4連で16×16の大画面(?)にあわせて下準備します。

8×8では表示させるデータを

const byte IMAGE_T[8]=
{//T
B11111100,
B10110100,
B00110000,
B00110000,
B00110000,
B00110000,
B01111000,
B00000000
};

のようにbyte 型で、要素数8個の配列で書いていますが、今度は16ドットなので、unsigned int 型、要素数16個の配列にしよう・・・

//エラーになりました
const unsigned int IMAGE_16[16]=
{//TA
//IW
B1111110000110000,
B1011010001111000,
B0011000011001100,
B0011000011001100,
B0011000011111100,
B0011000011001100,
B0111100011001100,
B0000000000000000,

B0111100011000110,
B0011000011000110,
B0011000011000110,
B0011000011010110,
B0011000011111110,
B0011000011101110,
B0111100011000110,
B0000000000000000
};

と思ったところ、こういう表記はできない、Bを頭に付けての二進表記はbyteまでなんだそうで。仕方ないので、こんな感じで、32要素のbyte配列で処理することにしましょう。

const unsigned int IMAGE_16T[32]=
{//TA
//IW
B11111100,B00110000,
B10110100,B01111000,
B00110000,B11001100,
B00110000,B11001100,
B00110000,B11111100,
B00110000,B11001100,
B01111000,B11001100,
B00000000,B00000000,

B01111000,B11000110,
B00110000,B11000110,
B00110000,B11000110,
B00110000,B11010110,
B00110000,B11111110,
B00110000,B11101110,
B01111000,B11000110,
B00000000,B00000000
};

TA
IW

と表示できるような関数を書いてやればいいわけですね。こんなふうに書いてみました。

#include <LedControl.h>

const int DIN_PIN = 7;
const int CS_PIN = 6;
const int CLK_PIN = 5;
const int DEVICES = 4;

const byte IMAGE_16x16[32]=
{//TA
//IW
B11111100,B00110000,
B10110100,B01111000,
B00110000,B11001100,
B00110000,B11001100,
B00110000,B11111100,
B00110000,B11001100,
B01111000,B11001100,
B00000000,B00000000,

B01111000,B11000110,
B00110000,B11000110,
B00110000,B11000110,
B00110000,B11010110,
B00110000,B11111110,
B00110000,B11101110,
B01111000,B11000110,
B00000000,B00000000
};

LedControl display = LedControl(DIN_PIN, CLK_PIN, CS_PIN, DEVICES);

void setup() {
int devices = display.getDeviceCount();
for(int address=0;address<devices;address++) {
  display.shutdown(address,false);
  display.setIntensity(address,0);
  display.clearDisplay(address);
}
displayImage16(IMAGE_16x16);
}

void displayImage(int device,const byte* image) {
for (int i = 0; i < 8; i++) {
 for (int j = 0; j < 8; j++) {
   display.setLed(device , i, j, bitRead(image[i], 7 - j));
 }
}
}

void displayImage16(const byte* imageL){
 byte Image0[8], Image1[8],Image2[8], Image3[8];
 for(int i = 0; i<8 ; i++){
   Image0[i]=imageL[2*i+16+1];
   Image1[i]=imageL[2*i+16];
   Image2[i]=imageL[2*i+1];
   Image3[i]=imageL[2*i];
 }
 displayImage(3, Image3);
 displayImage(2, Image2);
 displayImage(1, Image1);
 displayImage(0, Image0);
}

void loop() {

}


表示できました。

画像1


この記事が気に入ったらサポートをしてみませんか?