|
楼主 |
发表于 2020-2-21 10:00:07
|
显示全部楼层
- /*
- 【Arduino】168种传感器模块系列实验(资料 +代码 +图形 +仿真)
- 实验一百四十四:0.91寸OLED液晶屏显示模块 IIC
- 安装库:IDE—工具—管理库—搜索Adafruit_SSD1306—安装
- 安装库:IDE—工具—管理库—搜索Adafruit_GFX—安装
- 实验接线方法
- oled模块 Ardunio Uno
- GND---------GND接地线
- VCC---------5V 接电源
- SDA---------A4
- SCL ------- A5
- 实验之五:输出输出位图(及汉字位图)——实验室
- */
- #include <SPI.h>
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- #define OLED_RESET 4
- Adafruit_SSD1306 display(OLED_RESET);
- #if (SSD1306_LCDHEIGHT != 32)
- #endif
- #define NUMFLAKES 5
- #define XPOS 0
- #define YPOS 1
- #define DELTAY 2
- #define LOGO16_GLCD_HEIGHT 16
- #define LOGO16_GLCD_WIDTH 16
- static const unsigned char PROGMEM logo16_glcd_bmp[] =
- { B00000000, B11000000,
- B00000001, B11000000,
- B00000001, B11000000,
- B00000011, B11100000,
- B11110011, B11100000,
- B11111110, B11111000,
- B01111110, B11111111,
- B00110011, B10011111,
- B00011111, B11111100,
- B00001101, B01110000,
- B00011011, B10100000,
- B00111111, B11100000,
- B00111111, B11110000,
- B01111100, B11110000,
- B01110000, B01110000,
- B00000000, B00110000 };
- //中文:实
- static const unsigned char PROGMEM str_1[] = {
- 0x02,0x00,0x01,0x00,0x7F,0xFE,0x40,0x02,0x88,0x84,0x04,0x80,0x04,0x80,0x10,0x80,
- 0x08,0x80,0x08,0x80,0xFF,0xFE,0x01,0x40,0x02,0x20,0x04,0x10,0x18,0x08,0x60,0x04
- };
- //中文:验
- static const unsigned char PROGMEM str_2[] = {
- 0x00,0x20,0xF8,0x20,0x08,0x50,0x48,0x50,0x48,0x88,0x49,0x04,0x4A,0xFA,0x7C,0x00,
- 0x04,0x44,0x04,0x24,0x1D,0x24,0xE4,0xA8,0x44,0x88,0x04,0x10,0x2B,0xFE,0x10,0x00
- };
- //中文:室
- static const unsigned char PROGMEM str_3[] = {
- 0x02,0x00,0x01,0x00,0x7F,0xFE,0x40,0x02,0x80,0x04,0x3F,0xF8,0x04,0x00,0x08,0x20,
- 0x1F,0xF0,0x01,0x10,0x01,0x00,0x3F,0xF8,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00
- };
- void setup() {
- Serial.begin(115200);
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x64)
- display.display();
- delay(2000);
- }
- void loop() {
- display.clearDisplay();
- display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, WHITE);
- display.display();
- delay(2000);
- display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, BLACK);
- display.display();
- delay(500);
- display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, WHITE);
- display.display();
- delay(500);
- display.clearDisplay();
- display.drawBitmap(0, 0, str_1, 16, 16, WHITE);
- display.drawBitmap(16, 0, str_2, 16, 16, WHITE);
- display.drawBitmap(32, 0, str_3, 16, 16, WHITE);
- display.display();
- delay(2000);
- display.clearDisplay();
- testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
- }
- void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
- uint8_t icons[NUMFLAKES][3];
-
- // initialize
- for (uint8_t f=0; f< NUMFLAKES; f++) {
- icons[f][XPOS] = random(display.width());
- icons[f][YPOS] = 0;
- icons[f][DELTAY] = random(8) + 2;
-
- Serial.print("x: ");
- Serial.print(icons[f][XPOS], DEC);
- Serial.print(" y: ");
- Serial.print(icons[f][YPOS], DEC);
- Serial.print(" dy: ");
- Serial.println(icons[f][DELTAY], DEC);
- }
- while (1) {
- // draw each icon
- for (uint8_t f=0; f< NUMFLAKES; f++) {
- display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE);
- }
- display.display();
- delay(200);
-
- // then erase it + move it
- for (uint8_t f=0; f< NUMFLAKES; f++) {
- display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK);
- // move it
- icons[f][YPOS] += icons[f][DELTAY];
- // if its gone, reinit
- if (icons[f][YPOS] > display.height()) {
- icons[f][XPOS] = random(display.width());
- icons[f][YPOS] = 0;
- icons[f][DELTAY] = random(8) + 2;
- }
- }
- }
- }
复制代码 |
|