Xadow LED 5X7 点阵

From Wiki
Jump to: navigation, search

产品简介

该模块由一块Atmega168 和35颗呈5x7排列的LED灯组成,内置在Atmega168中的为你提供了丰富的接口函数, 你可以通过I2C总线发送控制命令给该模块,以控制LED灯的显示。 例如显示字母、数字,或者让其进入睡眠状态以降低功耗等。


300px-Xadow LED 01.jpg


规格参数

工作电压: 3.3V 内置微控制器Atmega168 控制方式: I2C 外形尺寸: 25.43mm x 20.35mm 应用示例

正如在产品简介部分描述的,LED可以显示字母和数字。下面我们就开始做这个有趣的demo。 硬件连接:


XadowLED5X7.jpg


测试代码:

  1. include "Wire.h"
  2. define XADOW_DEBUG 1
  3. define LEDAddress 0x04
  1. define DISP_CHAR_5X7 0x80
  2. define DISP_STRING 0x81
  3. define SET_DISP_ORIENTATION 0x82

/*Marco definitions for the display orientation of the LED matrix*/

  1. define RIGHT_TO_LEFT 0
  2. define LEFT_TO_RIGHT 1
  3. define POWER_DOWN 0x83

uint8_t buffer[24]; int error; int n; void setup(void) { Wire.begin(); delay(100); TESTIO(); if(error==0) {

 DDRB|=0x80;
 PORTB&=~0x80;
}

} void loop(void) { for(n=0;n<100;n++) {

 dispString("ABCDEF1234",1,1000);
 delay(100);

} //display the "seeed0728"(9 characters) on the //Xadow LED and the character moving one step costs 150m


}

/**********************************************************************/ /*Function: Send command to Xadow LED to display a string by the I2C. */ /*Parameter:-char* data_,Store a string to display on the xadow LED. */ /* -uint8_t len,The length of the data_. */ /* -uint16_t time,The time of the character moving one step. */ /*Return: void */ void dispString(char* data_,uint8_t len,uint16_t time) { Wire.beginTransmission(LEDAddress); Wire.write(DISP_STRING); Wire.write(len); Wire.write((uint8_t*)data_,len); Wire.write(time>>8); //high byte of time Wire.write(time);//low byte of time Wire.endTransmission(); } void dispChar(uint8_t data_,uint16_t time) { Wire.beginTransmission(LEDAddress); Wire.write(DISP_CHAR_5X7); Wire.write(data_); Wire.write(time>>8); //high byte of time Wire.write(time);//low byte of time Wire.endTransmission(); } void setDispOrientation(uint8_t orientation) { Wire.beginTransmission(LEDAddress); Wire.write(SET_DISP_ORIENTATION); Wire.write(orientation); Wire.endTransmission(); } void powerDown() { Wire.beginTransmission(LEDAddress); Wire.write(POWER_DOWN); Wire.endTransmission(); digitalWrite(3,HIGH); } void wakeUp() { Wire.beginTransmission(LEDAddress); Wire.endTransmission(); }


void TESTIO(void) {

 DDRB|=0x0e;
 PORTB&=~0x0e;
 DDRF|=0x01;
 PORTF&=~0x01;
 DDRD&=~0x0f;
 PORTB|=0x04;
 PORTF|=0x01;
 delay(30);

if(!(PIND&0x01)) {

 error=1;

} if(PIND&0x02) {

 error=1;

} if(!(PIND&0x04)) {

 error=1;

} if(PIND&0x08) {

 error=1;

}

PORTB&=~0x04;
PORTB|=0x0a;
PORTF&=~0x01;
delay(30);

if(PIND&0x01) {

 error=1;

} if(!(PIND&0x02)) {

 error=1;

} if(PIND&0x04) {

error=1;

} if(!(PIND&0x08)) {

error=1;

} Serial.println(error); } 下载程序后的效果图:

LED Effect Diagram .jpg