BLYNK TEST

Dependencies:   mbed Blynk

Committer:
lixianyu
Date:
Wed Jun 15 03:08:40 2016 +0000
Revision:
2:6cd3b0947188
Parent:
1:0e75de2a5d21
Child:
3:4cd9171ba989
PM2.5????????5V??????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lixianyu 0:d8f4c441e032 1 #include "mbed.h"
lixianyu 1:0e75de2a5d21 2
lixianyu 2:6cd3b0947188 3 #include "MicroduinoPinNames.h"
lixianyu 2:6cd3b0947188 4 DigitalOut myled(P0_20);
lixianyu 2:6cd3b0947188 5 I2C g_i2c(P0_11, P0_10);//SDA, SCL
lixianyu 2:6cd3b0947188 6 #if 1
lixianyu 2:6cd3b0947188 7 #include "SimpleTimer.h"
lixianyu 0:d8f4c441e032 8 #include "userDef.h"
lixianyu 0:d8f4c441e032 9 #include "sensor.h"
lixianyu 0:d8f4c441e032 10 #include "oled.h"
lixianyu 2:6cd3b0947188 11 #endif
lixianyu 1:0e75de2a5d21 12 //#include "WiFiBlynk.h"
lixianyu 2:6cd3b0947188 13
lixianyu 2:6cd3b0947188 14 //Serial pc(P0_4, P0_0); // tx, rx
lixianyu 2:6cd3b0947188 15
lixianyu 2:6cd3b0947188 16 Timer g_Timer;
lixianyu 0:d8f4c441e032 17
lixianyu 2:6cd3b0947188 18 void led_flash()
lixianyu 2:6cd3b0947188 19 {
lixianyu 2:6cd3b0947188 20 static int count = 0;
lixianyu 2:6cd3b0947188 21 count++;
lixianyu 2:6cd3b0947188 22 //pc.printf("count : %d, ms : %d\r\n", count, g_Timer.read_ms());
lixianyu 2:6cd3b0947188 23 //myled = 1;
lixianyu 2:6cd3b0947188 24 wait_ms(70);
lixianyu 2:6cd3b0947188 25 myled = 0;
lixianyu 2:6cd3b0947188 26 }
lixianyu 2:6cd3b0947188 27
lixianyu 2:6cd3b0947188 28 Adafruit_SSD1306_I2c adaf(g_i2c, P0_13, 0x78, 64, 128);
lixianyu 2:6cd3b0947188 29 void update_oled()
lixianyu 2:6cd3b0947188 30 {
lixianyu 2:6cd3b0947188 31 myled = 1;
lixianyu 2:6cd3b0947188 32 wait_ms(70);
lixianyu 2:6cd3b0947188 33 myled = 0;
lixianyu 2:6cd3b0947188 34 oled(adaf, sensor_tem, sensor_hum, sensor_light, sensorPM25, Sensor_etoh);
lixianyu 2:6cd3b0947188 35 }
lixianyu 2:6cd3b0947188 36
lixianyu 0:d8f4c441e032 37 int main()
lixianyu 0:d8f4c441e032 38 {
lixianyu 2:6cd3b0947188 39 //pc.baud(9600);
lixianyu 2:6cd3b0947188 40 //myled = 1;
lixianyu 0:d8f4c441e032 41 g_Timer.start();
lixianyu 2:6cd3b0947188 42 SimpleTimer gSimpleTimer(g_Timer);
lixianyu 2:6cd3b0947188 43
lixianyu 0:d8f4c441e032 44 //Serial.begin(9600); // See the connection status in Serial Monitor
lixianyu 0:d8f4c441e032 45 // Set ESP8266 baud rate
lixianyu 0:d8f4c441e032 46 //EspSerial.begin(115200);
lixianyu 0:d8f4c441e032 47
lixianyu 0:d8f4c441e032 48 //Blynk.begin(auth, wifi, SSID, PASS);
lixianyu 0:d8f4c441e032 49
lixianyu 0:d8f4c441e032 50 // Setup a function to be called every second
lixianyu 2:6cd3b0947188 51 //gSimpleTimer.setInterval(2000L, senTempHumi);
lixianyu 2:6cd3b0947188 52 gSimpleTimer.setInterval(1000, updateLight);
lixianyu 2:6cd3b0947188 53 gSimpleTimer.setInterval(5000, updateCH4);
lixianyu 2:6cd3b0947188 54 gSimpleTimer.setInterval(4000, updateTempHumi);
lixianyu 2:6cd3b0947188 55 //gSimpleTimer.setInterval(3000, PM25);
lixianyu 2:6cd3b0947188 56 //gSimpleTimer.setInterval(4000, led_flash);
lixianyu 2:6cd3b0947188 57 gSimpleTimer.setInterval(1000, update_oled);
lixianyu 2:6cd3b0947188 58
lixianyu 2:6cd3b0947188 59 //PM25_init();
lixianyu 1:0e75de2a5d21 60 wait_ms(2000);
lixianyu 2:6cd3b0947188 61 oled_init(adaf);
lixianyu 2:6cd3b0947188 62 int pretime = g_Timer.read_ms();
lixianyu 0:d8f4c441e032 63 while(1) {
lixianyu 2:6cd3b0947188 64 //pc.printf("Enter while(1)\r\n");
lixianyu 2:6cd3b0947188 65 //myled = !myled;
lixianyu 0:d8f4c441e032 66 //Blynk.run(); // All the Blynk Magic happens here...
lixianyu 2:6cd3b0947188 67 gSimpleTimer.run();
lixianyu 2:6cd3b0947188 68 #if 0
lixianyu 2:6cd3b0947188 69 int curtime = g_Timer.read_ms();
lixianyu 2:6cd3b0947188 70 if (curtime - pretime > 4000) {
lixianyu 2:6cd3b0947188 71 //updateTempHumi();
lixianyu 2:6cd3b0947188 72 led_flash();
lixianyu 2:6cd3b0947188 73 pretime = curtime;
lixianyu 0:d8f4c441e032 74 }
lixianyu 1:0e75de2a5d21 75 #endif
lixianyu 1:0e75de2a5d21 76
lixianyu 0:d8f4c441e032 77 }
lixianyu 0:d8f4c441e032 78 }