“8*8点阵模块”的版本间的差异

来自YFRobotwiki
跳转至: 导航搜索
第65行: 第65行:
 
<pre >
 
<pre >
 
/**************************************************
 
/**************************************************
  * 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))
第82行: 第83行:
 
//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() {
第102行: 第111行:
  
 
void doubleBuffer() {
 
void doubleBuffer() {
   row[screenRow]=0;
+
   row[screenRow] = 0;
   col[screenCol]=1;
+
   col[screenCol] = 1;
  
 
   screenCol++;
 
   screenCol++;
第113行: 第122行:
 
     }
 
     }
 
   }
 
   }
   if((screen[screenRow] >> screenCol) & B1 == B1) {
+
   if ((screen[screenRow] >> screenCol) & B1 == B1) {
     row[screenRow]=1;
+
     row[screenRow] = 1;
     col[screenCol]=0;
+
     col[screenCol] = 0;
     digitalWrite(RCK,LOW);
+
     digitalWrite(RCK, LOW);
     shiftOut(COL_DATA);
+
     shiftOut(SER, SRCK, MSBFIRST, COL_DATA); //先选择列
     shiftOut(ROW_DATA);
+
     shiftOut(SER, SRCK, MSBFIRST, ROW_DATA); //再送行数据
     digitalWrite(RCK,HIGH);
+
     digitalWrite(RCK, HIGH);
   }  
+
   }
 
}
 
}
  
 
void allOFF() {
 
void allOFF() {
 
   for (int i = 0; i < 8; i++)
 
   for (int i = 0; i < 8; i++)
     screen[i] = B00000000;
+
     screen[i] = B0;
 
}
 
}
  
第131行: 第140行:
 
   for (int i = 0; i < 8; i++)
 
   for (int i = 0; i < 8; i++)
 
     screen[i] = B11111111;
 
     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();
 
   allOFF();
 
}
 
}
  
void smile()
+
void UpdataDate() {
{
+
   if (animationIndex < animationFrames) {
   on(1, 1);on(1, 2);on(1, 7);on(1, 8);
+
    for (int i = 0; i < 64; i++) {
  on(2, 1);on(2, 2);on(2, 7);on(2, 8);
+
      brightnesses[i] = (animation[animationIndex][i / 4] >> (i % 4 * 2)) & B1;
  on(4, 4);on(4, 5);on(5, 4);on(5, 5);
+
      screen[7-i / 8] |= (brightnesses[i] << (i % 8)) ;
  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
+
void shiftOut(byte myDataOut) {
+
  //internal function setup
+
  boolean pinState;
+
 
+
  //clear shift register read for sending data
+
  digitalWrite(RCK, LOW);
+
  // 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 {      
+
     delay(animationDelays[animationIndex]);
       pinState= LOW;
+
     animationIndex ++;
 +
    if (animationIndex >= animationFrames) {
 +
      //restart animation index
 +
       animationIndex = 0;
 
     }
 
     }
    //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>
 
</pre>

2015年10月15日 (四) 14:18的版本

生成缩略图出错:文件可能丢失:
点阵模块


产品简介


8*8点阵模块是采用2片74HC595芯片驱动红色8X8点阵管,只需要使用控制器3路IO口,根据点阵管动态扫描原理进行显示,可以显示多种图案。


规格参数


  • 供电电压: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



示例代码

示例一:基本显示

/**************************************************
 * 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))

//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() {
  row[screenRow] = 0;
  col[screenCol] = 1;

  screenCol++;
  if (screenCol >= 8) {
    screenCol = 0;
    screenRow++;
    if (screenRow >= 8) {
      screenRow = 0;
    }
  }
  if ((screen[screenRow] >> screenCol) & 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 allOFF() {
  for (int i = 0; i < 8; i++)
    screen[i] = B0;
}

void allON() {
  for (int i = 0; i < 8; i++)
    screen[i] = B11111111;
}

void loop() {
  UpdataDate();
  allOFF();
}

void UpdataDate() {
  if (animationIndex < animationFrames) {
    for (int i = 0; i < 64; i++) {
      brightnesses[i] = (animation[animationIndex][i / 4] >> (i % 4 * 2)) & B1;
      screen[7-i / 8] |= (brightnesses[i] << (i % 8)) ;
    }
    delay(animationDelays[animationIndex]);
    animationIndex ++;
    if (animationIndex >= animationFrames) {
      //restart animation index
      animationIndex = 0;
    }
  }
}


程序下载地址:Face

程序运行结果:点阵模块显示笑脸~


点阵模块配合按键模块,做打乒乓游戏!请移步下面网址查看:Arduino驱动8*8点阵模块 附原理图及一个打乒乓球的游戏代码



参考资料





返回首页

更多建议和问题欢迎反馈至 YFRobot论坛

购买方式:YFRobot 电子工作室