8x8矩陣顯示器實習(2)-跑跑小藍人
8x8矩陣顯示器實習-跑跑小藍人
材料:
Arduino uno x1
8x8矩陣顯示模組(內含max7219)
接線方式:
圖片來源於:https://create.arduino.cc/projecthub/CiferTech/8x8-led-matrix-tutorial-project-code-and-schematic-969e60
觀念速記
控制顯示器的閘門主要是max7219,在一開始時先設定好max7219
的暫存器的設定值,包含了{顯示強度, 顯示檢測, 解碼, 停機, 掃描
限制,不運作},運送資料的方式類似寄送mail,首先要有郵址,該信件
傳送到該擁有者,開啓信件觀看到內容.所以傳送資料的方式是先
把SS設定為0,CLK時脈計算同步時間,MOSI,MISO傳送資料的收發.
程式碼
- #include <SPI.h>
- const byte actionLed[8][8]={
- {0x00,0x8b,0xef,0x3c,0x18,0xa0,0xc0,0x00}, //1
- {0x00,0xdb,0x6f,0x3c,0x18,0x28,0xd0,0x00}, //2
- {0x10,0x4b,0x5f,0x3c,0x28,0x48,0xd0,0x00}, //3
- {0x53,0x4f,0x3c,0x18,0x28,0x48,0x90,0x00}, //4
- {0x93,0x8f,0xfc,0x38,0x28,0x50,0xe0,0x00}, //5
- {0x93,0xcf,0x3c,0x38,0x48,0xd0,0x20,0x00}, //6
- {0x03,0x5f,0xbc,0x78,0xc8,0x30,0x00,0x00}, //7
- {0x00,0x03,0x0f,0x7c,0x58,0xe0,0x00,0x00} //8
- };
- //定義max7219暫存器
- const byte NOOP=0x0;
- const byte DECODEMODE=0X9;
- const byte INTENSITY=0xA;
- const byte SCANLIMIT=0xB;
- const byte SHUTDOWN=0xC;
- const byte DISPLAYTEST=0xF;
- //max7219函式
- void max7219(byte reg, byte data){
- digitalWrite(SS, LOW);
- SPI.transfer(reg);
- SPI.transfer(data);
- digitalWrite(SS, HIGH);
- }
- void setup(){
- SPI.begin();
- max7219(SCANLIMIT, 7);
- max7219(DECODEMODE, 0);
- max7219(INTENSITY, 6);
- max7219(DISPLAYTEST, 0);
- max7219(SHUTDOWN, 1);
- for (int i=0; i<8; i++){
- max7219(i+1, 0);
- }
- }
- void loop(){
- for (int j=0; j<8; j++){
- for (int i=0; i<8; i++){
- max7219(i+1, actionLed[j][i]);
- }
- delay(500);
- }
- }
留言
張貼留言