8*8点阵模块:修訂版本之間的差異

從 YFRobotwiki
跳到: 導覽搜尋
 
(由2名用戶作出的19個中途修訂版本未被顯示)
第 1 行: 第 1 行:
  
[[Image:点阵模块.jpg|400px|thumb|点阵模 ]]
+
[[Image:点阵模块.jpg|400px|thumb|点阵模 块V1]]
  
  
第 7 行: 第 7 行:
 
<br>
 
<br>
 
8*8点阵模块是采用2片74HC595芯片驱动红色8X8点阵管,只需要使用控制器3路IO口,根据点阵管动态扫描原理进行显示,可以显示多种图案。
 
8*8点阵模块是采用2片74HC595芯片驱动红色8X8点阵管,只需要使用控制器3路IO口,根据点阵管动态扫描原理进行显示,可以显示多种图案。
 +
 +
<font red >
 +
<font color="red">'''更新:新版模块使用PH2.0-5P接口,连接更加方便,使用方法相同。'''</font>
  
  
第 30 行: 第 33 行:
 
=== 应用示例 ===
 
=== 应用示例 ===
 
<br>
 
<br>
'''电路连接 示意图'''
+
'''电路连接'''
 
<br>
 
<br>
:'''点阵模块''' 的 VCC,GND,SER,RCK,SRCK 分别连接 '''Arduino UNO''' 的VCC(+5V)、GND、D10、D11、D12引脚。
+
 
 +
{|border="1" cellspacing="0" align="center" cellpadding="5" width="700px"
 +
|-
 +
|align="left"|'''点阵模块'''
 +
|align="left"|'''Arduino UNO'''
 +
|-
 +
|align="left"|VCC
 +
|align="left"|+5V
 +
|-
 +
|align="left"|GND
 +
|align="left"|GND
 +
|-
 +
|align="left"|SER
 +
|align="left"|D10
 +
|-
 +
|align="left"|RCK
 +
|align="left"|D11
 +
|-
 +
|align="left"|SRCK
 +
|align="left"|D12
 +
 
 +
|}
 
   
 
   
<!--[[Image: 点阵模块接线图.jpg|400px|center|点阵模块模块接线图]]-->
 
  
 +
'''电路连接示意图'''
  
 +
<img src="http://yfrobot.gitee.io/wiki/img/点阵显示.png"  alt="点阵显示" />
 +
 +
 +
库函数下载:[https://eyun.baidu.com/s/3o7EWj70 TimerOne]
  
 
'''示例代码'''
 
'''示例代码'''
 
<br><br>
 
<br><br>
 
<font color="darkcyan">'''示例一'''</font>:基本显示
 
<font color="darkcyan">'''示例一'''</font>:基本显示
<br>
+
<br><br>
<pre >
+
<font color="seagreen">'''Face.ino:'''</font>
 +
<source lang="c">
 
/**************************************************
 
/**************************************************
* Face  
+
  Face
* ( 8x8 Led Dot Matrix with two 74HC595 on Arduino)
+
  ( 8x8 Led Dot Matrix with two 74HC595 on Arduino)
*
+
 
* by YFROBOT  
+
  by YFROBOT
 
  ***************************************************/
 
  ***************************************************/
  
 
#include "TimerOne.h"
 
#include "TimerOne.h"
 
+
#include "face.h"
 +
// 默认显示
 
#define ROW_DATA ((row[0]<<7)|(row[1]<<6)|(row[2]<<5)|(row[3]<<4)|(row[4]<<3)|(row[5]<<2)|(row[6]<<1)|(row[7]<<0))
 
#define ROW_DATA ((row[0]<<7)|(row[1]<<6)|(row[2]<<5)|(row[3]<<4)|(row[4]<<3)|(row[5]<<2)|(row[6]<<1)|(row[7]<<0))
 
#define COL_DATA ((col[0]<<7)|(col[1]<<6)|(col[2]<<5)|(col[3]<<4)|(col[4]<<3)|(col[5]<<2)|(col[6]<<1)|(col[7]<<0))
 
#define COL_DATA ((col[0]<<7)|(col[1]<<6)|(col[2]<<5)|(col[3]<<4)|(col[4]<<3)|(col[5]<<2)|(col[6]<<1)|(col[7]<<0))
 +
// 垂直翻转
 +
//#define ROW_DATA ((row[0]<<0)|(row[1]<<1)|(row[2]<<2)|(row[3]<<3)|(row[4]<<4)|(row[5]<<5)|(row[6]<<6)|(row[7]<<7))
 +
//#define COL_DATA ((col[0]<<0)|(col[1]<<1)|(col[2]<<2)|(col[3]<<3)|(col[4]<<4)|(col[5]<<5)|(col[6]<<6)|(col[7]<<7))
 +
 +
// flip horizontal
 +
#define flip_horizontal 7-screenCol    // 默认显示
 +
//#define flip_horizontal screenCol      // 水平翻转
  
 
//Pin connected to DS of 74HC595
 
//Pin connected to DS of 74HC595
第 61 行: 第 98 行:
 
//Pin connected to SH_CP of 74HC595
 
//Pin connected to SH_CP of 74HC595
 
int SRCK  = 12;
 
int SRCK  = 12;
int row[8]={
+
int row[8] = {
   0, 0, 0, 0, 0, 0, 0, 0};
+
   0, 0, 0, 0, 0, 0, 0, 0
int col[8]={
+
};
   0, 0, 0, 0, 0, 0, 0, 0};
+
int col[8] = {
 +
   0, 0, 0, 0, 0, 0, 0, 0
 +
};
 
byte screen[8] = {
 
byte screen[8] = {
   0, 0, 0, 0, 0, 0, 0, 0};
+
   0, 0, 0, 0, 0, 0, 0, 0
 +
};
 
volatile byte screenRow = 0;
 
volatile byte screenRow = 0;
 
volatile byte screenCol = 0;
 
volatile byte screenCol = 0;
 +
 +
// A counter to know what frame we're showing
 +
int animationIndex = 0;
 +
// 8x8 Point temporary array
 +
byte brightnesses[64];
  
 
void setup() {
 
void setup() {
   Timer1.initialize(100);
+
   //  Timer1.initialize(100);
 
   pinMode(RCK, OUTPUT);
 
   pinMode(RCK, OUTPUT);
 
   pinMode(SRCK, OUTPUT);
 
   pinMode(SRCK, OUTPUT);
 
   pinMode(SER, OUTPUT);
 
   pinMode(SER, OUTPUT);
   Timer1.attachInterrupt(doubleBuffer);
+
   //  Timer1.attachInterrupt(doubleBuffer);
 
   Serial.begin(9600);
 
   Serial.begin(9600);
 
 
}
 
}
  
 
void doubleBuffer() {
 
void doubleBuffer() {
   row[screenRow]=0;
+
   int k = 8;
  col[screenCol]=1;
+
  while (k--) {
 +
    row[screenRow] = 0;
 +
    col[screenCol] = 1;
  
  screenCol++;
+
    screenCol++;
  if (screenCol >= 8) {
+
    if (screenCol >= 8) {
    screenCol = 0;
+
      screenCol = 0;
    screenRow++;
+
      screenRow++;
    if (screenRow >= 8) {
+
      if (screenRow >= 8) {
       screenRow = 0;
+
        screenRow = 0;
 +
       }
 +
    }
 +
 
 +
    if ((screen[screenRow] >> flip_horizontal) & B1 == B1) {
 +
      row[screenRow] = 1;
 +
      col[screenCol] = 0;
 +
      digitalWrite(RCK, LOW);
 +
      shiftOut(SER, SRCK, MSBFIRST, COL_DATA); //先选择列
 +
      shiftOut(SER, SRCK, MSBFIRST, ROW_DATA); //再送行数据
 +
      digitalWrite(RCK, HIGH);
 
     }
 
     }
 
   }
 
   }
  if((screen[screenRow] >> screenCol) & B1 == B1) {
 
    row[screenRow]=1;
 
    col[screenCol]=0;
 
    digitalWrite(RCK,LOW);
 
    shiftOut(COL_DATA);
 
    shiftOut(ROW_DATA);
 
    digitalWrite(RCK,HIGH);
 
  }
 
 
}
 
}
  
void allOFF() {
+
void UpdataDate() {
 +
  if (animationIndex < animationFrames) {
 +
    for (int i = 0; i < 64; i++) {
 +
      int Dot = (animation[animationIndex][i / 4] >> (i % 4 * 2));
 +
      brightnesses[i] = (Dot & B1) || (Dot & B10);
 +
      screen[7 - i / 8] |= (brightnesses[i] << (i % 8)) ;
 +
    }
 +
  }
 +
  unsigned long startime = millis();
 +
  while (millis() - startime < animationDelays[animationIndex])
 +
  {
 +
    doubleBuffer();
 +
  }
 +
  animationIndex ++;
 +
  if (animationIndex >= animationFrames) {
 +
    //restart animation index
 +
    animationIndex = 0;
 +
  }
 
   for (int i = 0; i < 8; i++)
 
   for (int i = 0; i < 8; i++)
     screen[i] = B00000000;
+
     screen[i] = B0;
}
+
 
+
void allON() {
+
  for (int i = 0; i < 8; i++)
+
    screen[i] = B11111111;
+
}
+
void on(byte row, byte column) {
+
  screen[column-1] |= (B1 << (row - 1));
+
}
+
 
+
void off(byte row, byte column) {
+
  screen[column-1] &= ~(B1 << (row - 1));
+
 
}
 
}
  
 
void loop() {
 
void loop() {
   smile();
+
   UpdataDate();
  allOFF();
+
  lol();
+
  allOFF();
+
 
}
 
}
 +
</source>
 +
<br>
 +
<font color="seagreen">'''face.h:'''</font>
 +
<br>
 +
<source lang="c">
 +
int animationFrames = 2;
  
void smile()
+
int animationDelays[] = { 1000, 1000 };
{
+
  on(1, 1);on(1, 2);on(1, 7);on(1, 8);
+
  on(2, 1);on(2, 2);on(2, 7);on(2, 8);
+
  on(4, 4);on(4, 5);on(5, 4);on(5, 5);
+
  on(7, 2);on(7, 7);
+
  on(8, 3);on(8, 4);on(8, 5);on(8, 6);
+
  delay(1000);
+
}
+
void lol()
+
{
+
  on(1,1);on(1,2);on(1,3);on(1,4);on(1,5);on(1,6);on(1,7);on(1,8);
+
  on(2,1);on(2,3);on(2,6);on(2,8);
+
  on(3,1);on(3,2);on(3,7);on(3,8);
+
  on(4,1);on(4,8);
+
  on(5,1);on(5,3);on(5,4);on(5,5);on(5,6);on(5,8);
+
  on(6,1);on(6,3);on(6,6);on(6,8);
+
  on(7,1);on(7,3);on(7,6);on(7,8);
+
  on(8,1);on(8,2);on(8,3);on(8,4);on(8,5);on(8,6);on(8,7);on(8,8);
+
  delay(1000);
+
}
+
  
//shift function
+
// Animation is designed for 8x8 pixels
void shiftOut(byte myDataOut) {
+
uint8_t animation[][16] = {
   //internal function setup
+
   { 0x55, 0x55, 0x11, 0x44, 0x5, 0x50, 0x1, 0x40, 0x51, 0x45, 0x11, 0x44, 0x11, 0x44, 0x55, 0x55 },
  boolean pinState;
+
  { 0x5, 0x50, 0x5, 0x50, 0x0, 0x0, 0x40, 0x1, 0x40, 0x1, 0x0, 0x0, 0x4, 0x10, 0x50, 0x5 }
 
+
};
  //clear shift register read for sending data
+
</source>
  digitalWrite(RCK, LOW);
+
 程序下载地址:[https://eyun.baidu.com/s/3qYkanve Face]
  // for each bit in dataOut send out a bit
+
  for (int i = 0; i <= 7; i++)  {
+
    //set clockPin to LOW prior to sending bit
+
    digitalWrite(SRCK, LOW);
+
    /*if the value of DataOut and (logical AND) a bitmask
+
    are true, set pinState to 1 (HIGH)*/
+
    if ( myDataOut & (1<<i) ) {
+
      pinState= HIGH;
+
    }
+
    else {    
+
      pinState= LOW;
+
    }
+
    //Sets the pin to HIGH or LOW depending on pinState
+
    digitalWrite(SER, pinState);
+
    //send bit out on rising edge of clock
+
    digitalWrite(SRCK, HIGH);
+
    digitalWrite(SER, LOW);
+
  }
+
  //stop shifting
+
  digitalWrite(SRCK, LOW);
+
}
+
 
+
</pre>
+
 程序下载地址:[ flameAlarm]
+
 
+
程序运行结果:
+
  
 +
程序运行结果:点阵模块显示笑脸和囧脸~
  
 +
[[File:囧脸.png]][[File:笑脸.png]]
 +
<br>
 +
<br>
 +
<font color="seagreen">'''face.h'''</font>文件通过[https://eyun.baidu.com/s/3jIDsGL4 点阵取模软件] 获得:
 +
<br>
 +
<br>
 +
[[File:点阵取模软件演示1.png]][[File:点阵取模软件演示2.png]]
 +
<br>
  
 +
<!--
 
'''示例代码'''
 
'''示例代码'''
 
<br><br>
 
<br><br>
 
<font color="darkcyan">'''示例二'''</font>:滚屏显示
 
<font color="darkcyan">'''示例二'''</font>:滚屏显示
 
<br>
 
<br>
<pre >
+
程序下载地址:[http://pan.baidu.com/s/1pJMkfIb Face]
  
</pre>
+
 程序运行结果: 点阵模块
程序下载地址:[ flameAlarm]
+
 
+
 程序运行结果:
+
  
  
第 201 行: 第 218 行:
 
<font color="darkcyan">'''示例三'''</font>:乒乓游戏
 
<font color="darkcyan">'''示例三'''</font>:乒乓游戏
 
<br>
 
<br>
<pre >
+
程序下载地址:
 +
-->
 +
 
  
</pre>
 
程序下载地址:[ flameAlarm]
 
  
  程序运行结果
+
  点阵模块滚屏显示,请移步 [http://www.yfrobot.com/thread-11735-1-1.html 点阵模块滚屏显示]
  
 +
点阵模块配合[http://www.yfrobot.com/wiki/index.php?title=%E6%AC%A7%E5%A7%86%E9%BE%99%E6%8C%89%E9%94%AE%E5%BC%80%E5%85%B3%E6%A8%A1%E5%9D%97 按键模块],做打乒乓游戏!请移步下面网址查看:[http://www.yfrobot.com/thread-2408-1-1.html Arduino驱动8*8点阵模块 附原理图及一个打乒乓球的游戏代码]
  
  
 +
乒乓游戏程序下载地址:[https://eyun.baidu.com/s/3qYE2wWG 乒乓游戏]
  
 
===参考资料===
 
===参考资料===
 
<br>
 
<br>
* [http://  点阵模块 电路 图]
+
* [[ Media:点阵模块 原理 .jpeg|点阵模块原理图 ]] [https://eyun.baidu.com/s/3gf9uWbL 备用地址]
* [http://pan.baidu.com/s/1pJORDAb 74HC595 datasheet]
+
* [https://eyun.baidu.com/s/3qYPrIOG 74HC595 datasheet]  [http://pan.baidu.com/s/1pJORDAb 备用地址]
* [http://pan.baidu.com/s/10pE4e 74HC595 中文数据手册]
+
* [https://eyun.baidu.com/s/3csAoUE 74HC595 中文数据手册]  [http://pan.baidu.com/s/10pE4e 备用地址]
  
  

2020年4月9日 (四) 08:42的最新修訂版本

創建縮圖錯誤: 檔案似乎遺失:
點陣模塊V1


產品簡介


8*8點陣模塊是採用2片74HC595芯片驅動紅色8X8點陣管,只需要使用控制器3路IO口,根據點陣管動態掃描原理進行顯示,可以顯示多種圖案。

更新:新版模塊使用PH2.0-5P接口,連接更加方便,使用方法相同。


規格參數


  • 供電電壓:DC5V
  • 使用芯片:74HC595
  • 模塊尺寸:32.5*32.5*14.7MM(長*寬*高)
  • 模塊重量:10.6g


引腳說明


  • 1. VCC -- Vcc(電源+5V)
  • 2. GND -- Gnd(地)
  • 3. SER -- 串行移位輸入
  • 4. RCK -- 存儲寄存器的時序輸入
  • 5. SRCK -- 移位寄存器的時序輸入


應用示例


電路連接

點陣模塊 Arduino UNO
VCC +5V
GND GND
SER D10
RCK D11
SRCK D12


電路連接示意圖

點陣顯示


庫函數下載:TimerOne

示例代碼

示例一:基本顯示

Face.ino:

/**************************************************
   Face
   ( 8x8 Led Dot Matrix with two 74HC595 on Arduino)
 
   by YFROBOT
 ***************************************************/
 
#include "TimerOne.h"
#include "face.h"
// 默认显示
#define ROW_DATA ((row[0]<<7)|(row[1]<<6)|(row[2]<<5)|(row[3]<<4)|(row[4]<<3)|(row[5]<<2)|(row[6]<<1)|(row[7]<<0))
#define COL_DATA ((col[0]<<7)|(col[1]<<6)|(col[2]<<5)|(col[3]<<4)|(col[4]<<3)|(col[5]<<2)|(col[6]<<1)|(col[7]<<0))
// 垂直翻转
//#define ROW_DATA ((row[0]<<0)|(row[1]<<1)|(row[2]<<2)|(row[3]<<3)|(row[4]<<4)|(row[5]<<5)|(row[6]<<6)|(row[7]<<7))
//#define COL_DATA ((col[0]<<0)|(col[1]<<1)|(col[2]<<2)|(col[3]<<3)|(col[4]<<4)|(col[5]<<5)|(col[6]<<6)|(col[7]<<7))
 
// flip horizontal
#define flip_horizontal 7-screenCol    // 默认显示
//#define flip_horizontal screenCol      // 水平翻转
 
//Pin connected to DS of 74HC595
int SER = 10;
//Pin connected to ST_CP of 74HC595
int RCK  = 11;
//Pin connected to SH_CP of 74HC595
int SRCK  = 12;
int row[8] = {
  0, 0, 0, 0, 0, 0, 0, 0
};
int col[8] = {
  0, 0, 0, 0, 0, 0, 0, 0
};
byte screen[8] = {
  0, 0, 0, 0, 0, 0, 0, 0
};
volatile byte screenRow = 0;
volatile byte screenCol = 0;
 
// A counter to know what frame we're showing
int animationIndex = 0;
// 8x8 Point temporary array
byte brightnesses[64];
 
void setup() {
  //  Timer1.initialize(100);
  pinMode(RCK, OUTPUT);
  pinMode(SRCK, OUTPUT);
  pinMode(SER, OUTPUT);
  //  Timer1.attachInterrupt(doubleBuffer);
  Serial.begin(9600);
}
 
void doubleBuffer() {
  int k = 8;
  while (k--) {
    row[screenRow] = 0;
    col[screenCol] = 1;
 
    screenCol++;
    if (screenCol >= 8) {
      screenCol = 0;
      screenRow++;
      if (screenRow >= 8) {
        screenRow = 0;
      }
    }
 
    if ((screen[screenRow] >> flip_horizontal) & B1 == B1) {
      row[screenRow] = 1;
      col[screenCol] = 0;
      digitalWrite(RCK, LOW);
      shiftOut(SER, SRCK, MSBFIRST, COL_DATA); //先选择列
      shiftOut(SER, SRCK, MSBFIRST, ROW_DATA); //再送行数据
      digitalWrite(RCK, HIGH);
    }
  }
}
 
void UpdataDate() {
  if (animationIndex < animationFrames) {
    for (int i = 0; i < 64; i++) {
      int Dot = (animation[animationIndex][i / 4] >> (i % 4 * 2));
      brightnesses[i] = (Dot & B1) || (Dot & B10);
      screen[7 - i / 8] |= (brightnesses[i] << (i % 8)) ;
    }
  }
  unsigned long startime = millis();
  while (millis() - startime < animationDelays[animationIndex])
  {
    doubleBuffer();
  }
  animationIndex ++;
  if (animationIndex >= animationFrames) {
    //restart animation index
    animationIndex = 0;
  }
  for (int i = 0; i < 8; i++)
    screen[i] = B0;
}
 
void loop() {
  UpdataDate();
}


face.h:

int animationFrames = 2;
 
int animationDelays[] = { 1000, 1000 };
 
// Animation is designed for 8x8 pixels
uint8_t animation[][16] = {
  { 0x55, 0x55, 0x11, 0x44, 0x5, 0x50, 0x1, 0x40, 0x51, 0x45, 0x11, 0x44, 0x11, 0x44, 0x55, 0x55 },
  { 0x5, 0x50, 0x5, 0x50, 0x0, 0x0, 0x40, 0x1, 0x40, 0x1, 0x0, 0x0, 0x4, 0x10, 0x50, 0x5 }
};

程序下載地址:Face

程序運行結果:點陣模塊顯示笑臉和囧臉~

囧臉.png笑臉.png

face.h文件通過點陣取模軟件 獲得:

點陣取模軟件演示1.png點陣取模軟件演示2.png



點陣模塊滾屏顯示,請移步:點陣模塊滾屏顯示

點陣模塊配合按鍵模塊,做打乒乓遊戲!請移步下面網址查看:Arduino驅動8*8點陣模塊 附原理圖及一個打乒乓球的遊戲代碼


乒乓遊戲程序下載地址:乒乓遊戲

參考資料





返回首頁

更多建議和問題歡迎反饋至 YFRobot論壇

購買方式:YFRobot 電子工作室