* AM2321的取温度间隔得大于2s,否则,i2c会不工作了 * SimpleTimer有个bug,会导致两次快速的读温度,现在读温度函数里加了保护 * Blynk有个bug,会导致无法把数据传到服务器 * 现在可以正常工作了

Dependencies:   mbed

Committer:
lixianyu
Date:
Fri Jun 24 02:06:43 2016 +0000
Revision:
1:e34100dd6532
Parent:
0:740c1eb2df13
?Arduino??????????0~255??????LPC824????????????????

Who changed what in which revision?

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