用户工具

站点工具


ocrobot:kit:arduino_star_kit:tutorial018

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
ocrobot:kit:arduino_star_kit:tutorial018 [2017/04/07 10:03] – 外部编辑 127.0.0.1ocrobot:kit:arduino_star_kit:tutorial018 [2023/06/07 04:23] (当前版本) – 外部编辑 127.0.0.1
行 1: 行 1:
 +======使用IIC点阵显示数字======
 +<WRAP center round info 100%>
 +这个例程展示了如何使用IIC点阵显示数字。
 +</WRAP>
  
 +IIC 即Inter-Integrated Circuit(集成电路总线),这种总线类型是由飞利浦半导体公司在八十年代初设计出来的,主要是用来连接整体电路,IIC是一种多向控制总线,也就是说多个芯片可以连接到同一总线结构下,同时每个芯片都可以作为实时数据传输的控制源。这种方式简化了信号传输总线。
 +
 + IIC串行总线一般有两根信号线,一根是双向的数据线SDA,另一根是时钟线SCL。所有接到IIC总线设备上的串行数据SDA都接到总线的SDA上,各设备的时钟线SCL接到总线的SCL上。
 +
 + IIC总线是各种总线中使用信号线最少,并具有自动寻址、多主机时钟同步和仲裁等功能的总线。使用I2C总线连接各种模块十分方便灵活,我们未来介绍各种模块时会遇到大量的IIC模块。
 +
 +=====搭建电路======
 +用到OCROBOT IIC 8X8点阵,硬件连接如下图,VCC GND SDA SCL按照对应管脚接好即可。
 +{{:ocrobot:kit:arduino_star_kit:2014-5-19_15-35-51.png?nolink|}}
 +=====代码=====
 +<code cpp>
 +#include <Wire.h>
 +#include "Adafruit_LEDBackpack.h"
 +#include "Adafruit_GFX.h"
 +
 +Adafruit_BicolorMatrix matrix = Adafruit_BicolorMatrix();
 +
 +void setup() {
 +  Serial.begin(9600);
 +  Serial.println("8x8 LED Matrix Test");
 +
 +  matrix.begin(0x70);  // pass in the address
 +}
 +
 +static const uint8_t PROGMEM
 +smile_bmp[] =
 +
 +  B00111100,
 +  B01000010,
 +  B10100101,
 +  B10000001,
 +  B10100101,
 +  B10011001,
 +  B01000010,
 +  B00111100 }
 +,
 +neutral_bmp[] =
 +
 +  B00111100,
 +  B01000010,
 +  B10100101,
 +  B10000001,
 +  B10111101,
 +  B10000001,
 +  B01000010,
 +  B00111100 }
 +,
 +frown_bmp[] =
 +
 +  B00111100,
 +  B01000010,
 +  B10100101,
 +  B10000001,
 +  B10011001,
 +  B10100101,
 +  B01000010,
 +  B00111100 };
 +
 +void loop() {
 +  matrix.setRotation(3); 
 +  matrix.clear();
 +  matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_GREEN);
 +  matrix.writeDisplay();
 +  delay(500);
 +
 +  matrix.clear();
 +  matrix.drawBitmap(0, 0, neutral_bmp, 8, 8, LED_YELLOW);
 +  matrix.writeDisplay();
 +  delay(500);
 +
 +  matrix.clear();
 +  matrix.drawBitmap(0, 0, frown_bmp, 8, 8, LED_RED);
 +  matrix.writeDisplay();
 +  delay(500);
 +
 +  matrix.clear();      // clear display
 +  matrix.drawPixel(0, 0, LED_GREEN);  
 +  matrix.writeDisplay();  // write the changes we just made to the display
 +  delay(500);
 +
 +  matrix.clear();
 +  matrix.drawLine(0,0, 7,7, LED_YELLOW);
 +  matrix.writeDisplay();  // write the changes we just made to the display
 +  delay(500);
 +
 +  matrix.clear();
 +  matrix.drawRect(0,0, 8,8, LED_RED);
 +  matrix.fillRect(2,2, 4,4, LED_GREEN);
 +  matrix.writeDisplay();  // write the changes we just made to the display
 +  delay(500);
 +
 +  matrix.clear();
 +  matrix.drawCircle(3,3, 3, LED_YELLOW);
 +  matrix.writeDisplay();  // write the changes we just made to the display
 +  delay(500);
 +
 +  matrix.setTextWrap(false);  // we dont want text to wrap so it scrolls nicely
 +  matrix.setTextSize(1);
 +  matrix.setTextColor(LED_GREEN);
 +  matrix.setRotation(3);     //FANG XIANG 
 +  for (int8_t x=7; x>=-72; x--) {
 +    matrix.clear();
 +    matrix.setCursor(x,0);
 +    matrix.print("Hello OCROBOT");
 +    matrix.writeDisplay();
 +    delay(100);
 +  }
 +  matrix.setTextWrap(false);  // we dont want text to wrap so it scrolls nicely
 +  matrix.setTextSize(1);
 +  matrix.setTextColor(LED_YELLOW);
 +  matrix.setRotation(3);
 +  for (int8_t x=7; x>=-72; x--) {
 +    matrix.clear();
 +    matrix.setCursor(x,0);
 +    matrix.print("1234567890");
 +    matrix.writeDisplay();
 +    delay(100);
 +  }
 +  matrix.setTextWrap(false);  // we dont want text to wrap so it scrolls nicely
 +  matrix.setTextSize(1);
 +  matrix.setTextColor(LED_RED);
 +  matrix.setRotation(3);
 +  for (int8_t x=7; x>=-72; x--) {
 +    matrix.clear();
 +    matrix.setCursor(x,0);
 +    matrix.print("ha~! ha~! ha~!");
 +    matrix.writeDisplay();
 +    delay(100);
 +  }
 +}
 +</code>
 +<WRAP center round important 100%>
 +注意:
 +
 + 如果使用的IDE编译是提示Robot_Control什么什么编译报错,进入libraries文件夹找到Robot_Control与Robot_Motor两个文件夹,删除。就可以正常编译了。
 +
 + 这是因为与Robot_Control的函数名冲突了。。。
 +</WRAP>
 +{{youku>XNzE1OTM4NjI4?900x530}}
 +=====下载=====
 +库:{{:ocrobot:kit:arduino_star_kit:adafruit_gfx_library.zip|}}
 +
 +{{:ocrobot:kit:arduino_star_kit:adafruit_led_backpack_library.zip|}}
 +
 +[[ocrobot:kit:arduino_star_kit:main|返回上一级]]