本帖最后由 董董soul 于 2016-10-27 11:09 编辑
IIC 即Inter-Integrated Circuit(集成电路总线),这种总线类型是由飞利浦半导体公司在八十年代初设计出来的,主要是用来连接整体电路,IIC是一种多向控制总线,也就是说多个芯片可以连接到同一总线结构下,同时每个芯片都可以作为实时数据传输的控制源。这种方式简化了信号传输总线。
IIC串行总线一般有两根信号线,一根是双向的数据线SDA,另一根是时钟线SCL。所有接到IIC总线设备上的串行数据SDA都接到总线的SDA上,各设备的时钟线SCL接到总线的SCL上。
IIC总线是各种总线中使用信号线最少,并具有自动寻址、多主机时钟同步和仲裁等功能的总线。使用I2C总线连接各种模块十分方便灵活,我们未来介绍各种模块时会遇到大量的IIC模块。
这次我们就会用到OCROBOT IIC 8X8点阵,硬件连接如下图,VCC GND SDA SCL按照对应管脚接好即可。
- #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);
- }
- }
复制代码
注意:
如果使用的IDE编译是提示Robot_Control什么什么编译报错,进入libraries文件夹找到Robot_Control与Robot_Motor两个文件夹,删除。就可以正常编译了。
这是因为与Robot_Control的函数名冲突了。。。 |