hadif azli
/
TEST123
BLYNK TEST
main.cpp@1:0e75de2a5d21, 2016-06-13 (annotated)
- Committer:
- lixianyu
- Date:
- Mon Jun 13 02:21:11 2016 +0000
- Revision:
- 1:0e75de2a5d21
- Parent:
- 0:d8f4c441e032
- Child:
- 2:6cd3b0947188
u8glib???????????????????????????Adafruit_GFX????OLED????????bitmap??????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lixianyu | 0:d8f4c441e032 | 1 | #include "mbed.h" |
lixianyu | 1:0e75de2a5d21 | 2 | |
lixianyu | 0:d8f4c441e032 | 3 | #include "userDef.h" |
lixianyu | 0:d8f4c441e032 | 4 | #include "sensor.h" |
lixianyu | 0:d8f4c441e032 | 5 | #include "oled.h" |
lixianyu | 1:0e75de2a5d21 | 6 | //#include "WiFiBlynk.h" |
lixianyu | 1:0e75de2a5d21 | 7 | //#include "Adafruit_SSD1306.h" |
lixianyu | 0:d8f4c441e032 | 8 | |
lixianyu | 1:0e75de2a5d21 | 9 | //Serial pc(D1, D0); // tx, rx |
lixianyu | 0:d8f4c441e032 | 10 | DigitalOut myled(P0_13); |
lixianyu | 0:d8f4c441e032 | 11 | Timer g_Timer; |
lixianyu | 1:0e75de2a5d21 | 12 | //I2C g_i2c(P0_11, P0_10);//SDA, SCL |
lixianyu | 1:0e75de2a5d21 | 13 | //Adafruit_SSD1306_I2c adaf(g_i2c, P0_13, 0x78, 64, 128); |
lixianyu | 0:d8f4c441e032 | 14 | int main() |
lixianyu | 0:d8f4c441e032 | 15 | { |
lixianyu | 1:0e75de2a5d21 | 16 | //pc.baud(115200); |
lixianyu | 1:0e75de2a5d21 | 17 | //myled = 0; |
lixianyu | 0:d8f4c441e032 | 18 | int ms = 0; |
lixianyu | 0:d8f4c441e032 | 19 | g_Timer.start(); |
lixianyu | 1:0e75de2a5d21 | 20 | //U8GLIB_SSD1306_MICRODUINO_128X64 u8glibhehe(U8G_I2C_OPT_NONE); //设置OLED型号 |
lixianyu | 0:d8f4c441e032 | 21 | //Serial.begin(9600); // See the connection status in Serial Monitor |
lixianyu | 0:d8f4c441e032 | 22 | // Set ESP8266 baud rate |
lixianyu | 0:d8f4c441e032 | 23 | //EspSerial.begin(115200); |
lixianyu | 0:d8f4c441e032 | 24 | |
lixianyu | 0:d8f4c441e032 | 25 | //Blynk.begin(auth, wifi, SSID, PASS); |
lixianyu | 0:d8f4c441e032 | 26 | |
lixianyu | 0:d8f4c441e032 | 27 | // Setup a function to be called every second |
lixianyu | 0:d8f4c441e032 | 28 | //temHumtimer.setInterval(2000L, senTempHumi); |
lixianyu | 1:0e75de2a5d21 | 29 | wait_ms(1000); |
lixianyu | 1:0e75de2a5d21 | 30 | //Adafruit_SSD1306_I2c adaf(g_i2c, P0_13, 0x78, 64, 128); |
lixianyu | 1:0e75de2a5d21 | 31 | //Adafruit_SSD1306_I2c adaf(g_i2c, P0_13); |
lixianyu | 1:0e75de2a5d21 | 32 | wait_ms(2000); |
lixianyu | 1:0e75de2a5d21 | 33 | //u8glibhehe.init_u8g(); |
lixianyu | 1:0e75de2a5d21 | 34 | oled_init(); |
lixianyu | 0:d8f4c441e032 | 35 | while(1) { |
lixianyu | 1:0e75de2a5d21 | 36 | //printf("Enter while(1)\r\n"); |
lixianyu | 1:0e75de2a5d21 | 37 | myled = !myled; |
lixianyu | 0:d8f4c441e032 | 38 | //Blynk.run(); // All the Blynk Magic happens here... |
lixianyu | 0:d8f4c441e032 | 39 | //temHumtimer.run(); // Initiates SimpleTimer |
lixianyu | 0:d8f4c441e032 | 40 | |
lixianyu | 1:0e75de2a5d21 | 41 | //updateTempHumi(); |
lixianyu | 1:0e75de2a5d21 | 42 | //updateLight(); |
lixianyu | 1:0e75de2a5d21 | 43 | //updateCH4(); |
lixianyu | 0:d8f4c441e032 | 44 | |
lixianyu | 0:d8f4c441e032 | 45 | ms = g_Timer.read_ms(); |
lixianyu | 1:0e75de2a5d21 | 46 | #if 1 |
lixianyu | 0:d8f4c441e032 | 47 | if (pm25_time > ms) pm25_time = ms; |
lixianyu | 0:d8f4c441e032 | 48 | if (ms - pm25_time > INTERVAL_pm25) { |
lixianyu | 1:0e75de2a5d21 | 49 | //sensorPM25 = PM25(); |
lixianyu | 0:d8f4c441e032 | 50 | pm25_time = ms; //更新计时器 |
lixianyu | 0:d8f4c441e032 | 51 | } |
lixianyu | 1:0e75de2a5d21 | 52 | #endif |
lixianyu | 1:0e75de2a5d21 | 53 | #if 0 |
lixianyu | 1:0e75de2a5d21 | 54 | adaf.clearDisplay(); |
lixianyu | 1:0e75de2a5d21 | 55 | adaf.drawRect(1, 1, 30,30, WHITE); |
lixianyu | 1:0e75de2a5d21 | 56 | adaf.display(); |
lixianyu | 1:0e75de2a5d21 | 57 | #endif |
lixianyu | 1:0e75de2a5d21 | 58 | //drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); |
lixianyu | 1:0e75de2a5d21 | 59 | //oled(u8glibhehe, sensor_tem, sensor_hum, sensor_light, sensorPM25, Sensor_etoh); |
lixianyu | 0:d8f4c441e032 | 60 | oled(sensor_tem, sensor_hum, sensor_light, sensorPM25, Sensor_etoh); |
lixianyu | 1:0e75de2a5d21 | 61 | wait(0.1); |
lixianyu | 1:0e75de2a5d21 | 62 | |
lixianyu | 0:d8f4c441e032 | 63 | } |
lixianyu | 0:d8f4c441e032 | 64 | } |
lixianyu | 1:0e75de2a5d21 | 65 | |
lixianyu | 1:0e75de2a5d21 | 66 | /** Write to an I2C slave |
lixianyu | 1:0e75de2a5d21 | 67 | * |
lixianyu | 1:0e75de2a5d21 | 68 | * Performs a complete write transaction. The bottom bit of |
lixianyu | 1:0e75de2a5d21 | 69 | * the address is forced to 0 to indicate a write. |
lixianyu | 1:0e75de2a5d21 | 70 | * |
lixianyu | 1:0e75de2a5d21 | 71 | * @param address 8-bit I2C slave address [ addr | 0 ] |
lixianyu | 1:0e75de2a5d21 | 72 | * @param data Pointer to the byte-array data to send |
lixianyu | 1:0e75de2a5d21 | 73 | * @param length Number of bytes to send |
lixianyu | 1:0e75de2a5d21 | 74 | * @param repeated Repeated start, true - do not send stop at end |
lixianyu | 1:0e75de2a5d21 | 75 | * |
lixianyu | 1:0e75de2a5d21 | 76 | * @returns |
lixianyu | 1:0e75de2a5d21 | 77 | * 0 on success (ack), |
lixianyu | 1:0e75de2a5d21 | 78 | * non-0 on failure (nack) |
lixianyu | 1:0e75de2a5d21 | 79 | */ |
lixianyu | 1:0e75de2a5d21 | 80 | int i2c_write1(int address, const char *data, int length) |
lixianyu | 1:0e75de2a5d21 | 81 | { |
lixianyu | 1:0e75de2a5d21 | 82 | //return g_i2c.write(address, data, length); |
lixianyu | 1:0e75de2a5d21 | 83 | } |
lixianyu | 1:0e75de2a5d21 | 84 | |
lixianyu | 1:0e75de2a5d21 | 85 | void log(char *s) |
lixianyu | 1:0e75de2a5d21 | 86 | { |
lixianyu | 1:0e75de2a5d21 | 87 | printf("%s\r\n", s); |
lixianyu | 1:0e75de2a5d21 | 88 | } |
lixianyu | 1:0e75de2a5d21 | 89 | |
lixianyu | 1:0e75de2a5d21 | 90 | void open_led(void) |
lixianyu | 1:0e75de2a5d21 | 91 | { |
lixianyu | 1:0e75de2a5d21 | 92 | //myled = 1; |
lixianyu | 1:0e75de2a5d21 | 93 | } |
lixianyu | 1:0e75de2a5d21 | 94 | |
lixianyu | 1:0e75de2a5d21 | 95 | void close_led(void) |
lixianyu | 1:0e75de2a5d21 | 96 | { |
lixianyu | 1:0e75de2a5d21 | 97 | //myled = 0; |
lixianyu | 1:0e75de2a5d21 | 98 | } |