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