BLYNK TEST

Dependencies:   mbed Blynk

Committer:
lixianyu
Date:
Mon Jun 13 02:21:11 2016 +0000
Revision:
1:0e75de2a5d21
Child:
2:6cd3b0947188
u8glib???????????????????????????Adafruit_GFX????OLED????????bitmap??????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lixianyu 1:0e75de2a5d21 1 #include "mbed.h"
lixianyu 1:0e75de2a5d21 2 #include "Adafruit_SSD1306.h"
lixianyu 1:0e75de2a5d21 3 #include "oled.h"
lixianyu 1:0e75de2a5d21 4
lixianyu 1:0e75de2a5d21 5 I2C g_i2c(P0_11, P0_10);//SDA, SCL
lixianyu 1:0e75de2a5d21 6 Adafruit_SSD1306_I2c adaf(g_i2c, P0_13, 0x78, 64, 128);
lixianyu 1:0e75de2a5d21 7 //U8GLIB_SSD1306_MICRODUINO_128X64 u8g(U8G_I2C_OPT_NONE); //设置OLED型号
lixianyu 1:0e75de2a5d21 8 //-------字体设置,大、中、小
lixianyu 1:0e75de2a5d21 9 #if 0
lixianyu 1:0e75de2a5d21 10 #define setFont_L u8g.setFont(u8g_font_7x13)
lixianyu 1:0e75de2a5d21 11 #define setFont_M u8g.setFont(u8g_font_fixed_v0r)
lixianyu 1:0e75de2a5d21 12 #define setFont_S u8g.setFont(u8g_font_chikitar)
lixianyu 1:0e75de2a5d21 13 #elif 0
lixianyu 1:0e75de2a5d21 14 #define setFont_L adaf.setTextSize(14)
lixianyu 1:0e75de2a5d21 15 #define setFont_M adaf.setTextSize(10)
lixianyu 1:0e75de2a5d21 16 #define setFont_S adaf.setTextSize(6)
lixianyu 1:0e75de2a5d21 17 #else
lixianyu 1:0e75de2a5d21 18 #define setFont_L
lixianyu 1:0e75de2a5d21 19 #define setFont_M
lixianyu 1:0e75de2a5d21 20 #define setFont_S
lixianyu 1:0e75de2a5d21 21 #endif
lixianyu 1:0e75de2a5d21 22
lixianyu 1:0e75de2a5d21 23 //温度计图案
lixianyu 1:0e75de2a5d21 24 unsigned char bmp_tem[] = {
lixianyu 1:0e75de2a5d21 25 0xE0,0x81,0x30,0x83,0x10,0x82,0x10,0x82,0x10,0xFA,0x10,0x82,
lixianyu 1:0e75de2a5d21 26 0x10,0x82,0x10,0xFA,0x10,0x82,0xD0,0x82,0xD0,0xFA,0xD0,0x82,
lixianyu 1:0e75de2a5d21 27 0xD0,0x82,0xD0,0xFA,0xD0,0x82,0xD0,0x82,0xD0,0xFA,0xD0,0x82,
lixianyu 1:0e75de2a5d21 28 0xD0,0x82,0xD8,0x86,0xC4,0x88,0xF2,0x93,0xFB,0xB7,0xF9,0xA7,
lixianyu 1:0e75de2a5d21 29 0xFD,0xAF,0xFD,0xAF,0xF9,0xA7,0xFA,0x97,0xF2,0x93,0xC4,0x88,
lixianyu 1:0e75de2a5d21 30 0x18,0x86,0xF0,0x83
lixianyu 1:0e75de2a5d21 31 };
lixianyu 1:0e75de2a5d21 32
lixianyu 1:0e75de2a5d21 33 //水滴图案
lixianyu 1:0e75de2a5d21 34 unsigned char bmp_hum[] = {
lixianyu 1:0e75de2a5d21 35 0x00,0x00,0x01,0x00,0x00,0x01,0x00,0x80,0x03,0x08,0x80,0x03,0x18,0x80,0x07,0x1C,
lixianyu 1:0e75de2a5d21 36 0xC0,0x07,0x3C,0xC0,0x07,0x3E,0xE0,0x0F,0x3E,0xE0,0x0F,0x7A,0xF0,0x1F,0x7B,0xF8,
lixianyu 1:0e75de2a5d21 37 0x1F,0x72,0xF8,0x1F,0x3E,0xF8,0x3F,0x1C,0xFC,0x3F,0x00,0xFC,0x7F,0x00,0xFE,0x7F,
lixianyu 1:0e75de2a5d21 38 0x00,0xFE,0x7F,0x00,0xFE,0x7F,0x00,0xFF,0xFF,0x00,0xFF,0xFF,0x00,0xFF,0xFF,0x00,
lixianyu 1:0e75de2a5d21 39 0xF3,0xFF,0x00,0xF2,0x7F,0x00,0xE6,0x7F,0x00,0xC6,0x7F,0x00,0x0E,0x3F,0x00,0x3C,
lixianyu 1:0e75de2a5d21 40 0x1E,0x00,0xF8,0x1F,0x00,0xE0,0x07,0x00,0x80,0x01
lixianyu 1:0e75de2a5d21 41 };
lixianyu 1:0e75de2a5d21 42
lixianyu 1:0e75de2a5d21 43 void oled_init(void)
lixianyu 1:0e75de2a5d21 44 {
lixianyu 1:0e75de2a5d21 45 adaf.setTextColor(1, 0);
lixianyu 1:0e75de2a5d21 46 //adaf.setTextColor(0, 1);
lixianyu 1:0e75de2a5d21 47 adaf.setTextSize(1);
lixianyu 1:0e75de2a5d21 48 }
lixianyu 1:0e75de2a5d21 49
lixianyu 1:0e75de2a5d21 50 #if 0
lixianyu 1:0e75de2a5d21 51 void oled(float temp, float humi, float light, float pm25, float etoh)
lixianyu 1:0e75de2a5d21 52 //void oled(U8GLIB &u8g, float temp, float humi, float light, float pm25, float etoh)
lixianyu 1:0e75de2a5d21 53 {
lixianyu 1:0e75de2a5d21 54 //gpio_write(&g_LED, 1);
lixianyu 1:0e75de2a5d21 55 u8g.firstPage();
lixianyu 1:0e75de2a5d21 56 do {
lixianyu 1:0e75de2a5d21 57 u8g.setDefaultForegroundColor();
lixianyu 1:0e75de2a5d21 58
lixianyu 1:0e75de2a5d21 59 u8g.drawXBMP( 4, 1, 15, 32, bmp_tem);
lixianyu 1:0e75de2a5d21 60 u8g.drawXBMP( 70, 2, 24, 30, bmp_hum);
lixianyu 1:0e75de2a5d21 61
lixianyu 1:0e75de2a5d21 62 setFont_M; //设置字体为大
lixianyu 1:0e75de2a5d21 63 u8g.setPrintPos(20, 16); //设置文字开始坐标
lixianyu 1:0e75de2a5d21 64 u8g.print("`C ");
lixianyu 1:0e75de2a5d21 65 setFont_L; //设置字体为大
lixianyu 1:0e75de2a5d21 66 u8g.setPrintPos(20, 32); //设置文字开始坐标
lixianyu 1:0e75de2a5d21 67 u8g.print(temp , 1); //温度
lixianyu 1:0e75de2a5d21 68
lixianyu 1:0e75de2a5d21 69 u8g.setPrintPos(100, 16); //设置文字开始坐标
lixianyu 1:0e75de2a5d21 70 u8g.print("%");
lixianyu 1:0e75de2a5d21 71 setFont_L; //设置字体为大
lixianyu 1:0e75de2a5d21 72 u8g.setPrintPos(100, 32); //设置文字开始坐标
lixianyu 1:0e75de2a5d21 73 u8g.print(humi , 0); //湿度
lixianyu 1:0e75de2a5d21 74
lixianyu 1:0e75de2a5d21 75 setFont_L; //设置字体
lixianyu 1:0e75de2a5d21 76 u8g.setPrintPos(4, 49); //设置文字开始坐标
lixianyu 1:0e75de2a5d21 77 u8g.print(light , 0); //光照强度
lixianyu 1:0e75de2a5d21 78 setFont_M; //设置字体
lixianyu 1:0e75de2a5d21 79 u8g.print(" Lux");
lixianyu 1:0e75de2a5d21 80
lixianyu 1:0e75de2a5d21 81 setFont_L; //设置字体
lixianyu 1:0e75de2a5d21 82 u8g.setPrintPos(4, 63); //设置文字开始坐标
lixianyu 1:0e75de2a5d21 83 u8g.print(pm25 , 0); //光照强度
lixianyu 1:0e75de2a5d21 84 setFont_M; //设置字体
lixianyu 1:0e75de2a5d21 85 u8g.print(" ug/m3");
lixianyu 1:0e75de2a5d21 86
lixianyu 1:0e75de2a5d21 87
lixianyu 1:0e75de2a5d21 88 setFont_L; //设置字体
lixianyu 1:0e75de2a5d21 89 u8g.setPrintPos(80, 49); //设置文字开始坐标
lixianyu 1:0e75de2a5d21 90 u8g.print(etoh , 0); //光照强度
lixianyu 1:0e75de2a5d21 91 setFont_M; //设置字体
lixianyu 1:0e75de2a5d21 92 u8g.print(" ppm");
lixianyu 1:0e75de2a5d21 93
lixianyu 1:0e75de2a5d21 94 // setFont_M; //设置字体为大
lixianyu 1:0e75de2a5d21 95 // u8g.setPrintPos(80, 63); //设置文字开始坐标
lixianyu 1:0e75de2a5d21 96 // u8g.print(" LED:");
lixianyu 1:0e75de2a5d21 97
lixianyu 1:0e75de2a5d21 98 } while( u8g.nextPage() );
lixianyu 1:0e75de2a5d21 99 //gpio_write(&g_LED, 0);
lixianyu 1:0e75de2a5d21 100 }
lixianyu 1:0e75de2a5d21 101 #elif 1
lixianyu 1:0e75de2a5d21 102 void oled(float temp, float humi, float light, float pm25, float etoh)
lixianyu 1:0e75de2a5d21 103 {
lixianyu 1:0e75de2a5d21 104 adaf.clearDisplay();
lixianyu 1:0e75de2a5d21 105
lixianyu 1:0e75de2a5d21 106 //adaf.drawBitmap(4, 1, bmp_tem, 15, 32, WHITE);
lixianyu 1:0e75de2a5d21 107 //adaf.drawBitmap(70, 2, bmp_hum, 24, 30, WHITE);
lixianyu 1:0e75de2a5d21 108
lixianyu 1:0e75de2a5d21 109 temp = 32.2;
lixianyu 1:0e75de2a5d21 110 adaf.setTextCursor(0, 5); //设置文字开始坐标
lixianyu 1:0e75de2a5d21 111 adaf.printf("Temp:%.1f'C", temp);
lixianyu 1:0e75de2a5d21 112
lixianyu 1:0e75de2a5d21 113 light = 210.0;
lixianyu 1:0e75de2a5d21 114 adaf.setTextCursor(74, 5); //设置文字开始坐标
lixianyu 1:0e75de2a5d21 115 adaf.printf("%.1fLux", light); //光照强度
lixianyu 1:0e75de2a5d21 116
lixianyu 1:0e75de2a5d21 117 humi = 90.6;
lixianyu 1:0e75de2a5d21 118 adaf.setTextCursor(0, 30); //设置文字开始坐标
lixianyu 1:0e75de2a5d21 119 adaf.printf("Humi:%.1f%%", humi);
lixianyu 1:0e75de2a5d21 120
lixianyu 1:0e75de2a5d21 121 pm25 = 9.7;
lixianyu 1:0e75de2a5d21 122 adaf.printf(" %.1fug/m3", pm25); //PM2.5
lixianyu 1:0e75de2a5d21 123
lixianyu 1:0e75de2a5d21 124 etoh = 2.6;
lixianyu 1:0e75de2a5d21 125 adaf.setTextCursor(1, 52); //设置文字开始坐标
lixianyu 1:0e75de2a5d21 126 adaf.printf("%.1f ppm", etoh); //甲醛
lixianyu 1:0e75de2a5d21 127
lixianyu 1:0e75de2a5d21 128 adaf.drawFastVLine(69, 0, 63, WHITE);
lixianyu 1:0e75de2a5d21 129
lixianyu 1:0e75de2a5d21 130 adaf.display();
lixianyu 1:0e75de2a5d21 131 }
lixianyu 1:0e75de2a5d21 132 #else
lixianyu 1:0e75de2a5d21 133 void oled(float temp, float humi, float light, float pm25, float etoh)
lixianyu 1:0e75de2a5d21 134 {
lixianyu 1:0e75de2a5d21 135 static int16_t x = 0;
lixianyu 1:0e75de2a5d21 136 static int16_t y = 0;
lixianyu 1:0e75de2a5d21 137 adaf.clearDisplay();
lixianyu 1:0e75de2a5d21 138 //adaf.setTextColor(0, 1);
lixianyu 1:0e75de2a5d21 139 adaf.setTextCursor(x, y);
lixianyu 1:0e75de2a5d21 140 adaf.printf("Lux\r\n");
lixianyu 1:0e75de2a5d21 141 adaf.display();
lixianyu 1:0e75de2a5d21 142 x += 2;
lixianyu 1:0e75de2a5d21 143 if (x > 128) {
lixianyu 1:0e75de2a5d21 144 x = 0;
lixianyu 1:0e75de2a5d21 145 y += 2;
lixianyu 1:0e75de2a5d21 146 if (y > 64) {
lixianyu 1:0e75de2a5d21 147 y = 0;
lixianyu 1:0e75de2a5d21 148 }
lixianyu 1:0e75de2a5d21 149 }
lixianyu 1:0e75de2a5d21 150 }
lixianyu 1:0e75de2a5d21 151 #endif