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傳送資料的收發.

程式碼

  1. #include <SPI.h>
  2.  
  3. const byte actionLed[8][8]={
  4. {0x00,0x8b,0xef,0x3c,0x18,0xa0,0xc0,0x00}, //1
  5. {0x00,0xdb,0x6f,0x3c,0x18,0x28,0xd0,0x00}, //2
  6. {0x10,0x4b,0x5f,0x3c,0x28,0x48,0xd0,0x00}, //3
  7. {0x53,0x4f,0x3c,0x18,0x28,0x48,0x90,0x00}, //4
  8. {0x93,0x8f,0xfc,0x38,0x28,0x50,0xe0,0x00}, //5
  9. {0x93,0xcf,0x3c,0x38,0x48,0xd0,0x20,0x00}, //6
  10. {0x03,0x5f,0xbc,0x78,0xc8,0x30,0x00,0x00}, //7
  11. {0x00,0x03,0x0f,0x7c,0x58,0xe0,0x00,0x00} //8
  12. };
  13.  
  14. //定義max7219暫存器
  15. const byte NOOP=0x0;
  16. const byte DECODEMODE=0X9;
  17. const byte INTENSITY=0xA;
  18. const byte SCANLIMIT=0xB;
  19. const byte SHUTDOWN=0xC;
  20. const byte DISPLAYTEST=0xF;
  21.  
  22. //max7219函式
  23. void max7219(byte reg, byte data){
  24. digitalWrite(SS, LOW);
  25. SPI.transfer(reg);
  26. SPI.transfer(data);
  27. digitalWrite(SS, HIGH);
  28. }
  29.  
  30. void setup(){
  31. SPI.begin();
  32.  
  33. max7219(SCANLIMIT, 7);
  34. max7219(DECODEMODE, 0);
  35. max7219(INTENSITY, 6);
  36. max7219(DISPLAYTEST, 0);
  37. max7219(SHUTDOWN, 1);
  38.  
  39. for (int i=0; i<8; i++){
  40. max7219(i+1, 0);
  41. }
  42. }
  43.  
  44. void loop(){
  45. for (int j=0; j<8; j++){
  46. for (int i=0; i<8; i++){
  47. max7219(i+1, actionLed[j][i]);
  48. }
  49. delay(500);
  50. }
  51. }

實作成果




留言

這個網誌中的熱門文章

平衡小車(balance-Robot)-基本平衡-Arduino