Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* 00002 * Io_moon(木卫一) is a project name. 00003 * Io_moon port ESP8266BlynkWeatherStation from Microduino Core+ to LPC824. 00004 * 00005 * ref: 00006 * http://wiki.microduino.cn/index.php/开源WiFi气象站系统/zh 00007 * https://github.com/Microduino/ESP8266BlynkWeatherStation 00008 */ 00009 #include "mbed.h" 00010 00011 #include "Config.h" 00012 #include "MicroduinoPinNames.h" 00013 DigitalOut myled(P0_20); 00014 I2C g_i2c(P0_11, P0_10);//SDA, SCL 00015 Timer g_MainTimer; 00016 Ticker g_Ticker; 00017 #include "SimpleTimer.h" 00018 #include "userDef.h" 00019 #include "sensor.h" 00020 #ifdef OPEN_OLED 00021 #include "oled.h" 00022 #endif 00023 #ifdef OPEN_BLYNK 00024 #include "WiFiBlynk.h" 00025 #endif 00026 Serial pc(P0_4, P0_0); // tx, rx 00027 00028 void led_flash() 00029 { 00030 #if 0 00031 static int cot = 0; 00032 cot++; 00033 if (cot > 4) { 00034 g_Timer.reset(); 00035 cot = 0; 00036 } 00037 #endif 00038 myled = 1; 00039 wait_ms(70); 00040 myled = 0; 00041 } 00042 00043 static void led_flash_fast() 00044 { 00045 myled = !myled; 00046 } 00047 00048 #ifdef OPEN_OLED 00049 Adafruit_SSD1306_I2c adaf(g_i2c, P0_13, 0x78, 64, 128); 00050 void update_oled() 00051 { 00052 static uint32_t start; 00053 start = g_MainTimer.read_ms(); 00054 //pc.printf("update_oled: %u ms\r\n", start); 00055 myled = 1; 00056 wait_ms(60); 00057 myled = 0; 00058 oled(adaf, sensor_tem, sensor_hum, sensor_light, sensorPM25, Sensor_etoh); 00059 } 00060 #endif 00061 00062 int main() 00063 { 00064 g_Ticker.attach_us(led_flash_fast, 40000); 00065 pc.baud(115200); 00066 pc.printf("Enter main()\r\n"); 00067 g_MainTimer.start(); 00068 SimpleTimer gSimpleTimer; 00069 00070 // Setup a function to be called every second 00071 #ifdef OPEN_BLYNK 00072 gSimpleTimer.setInterval(2000, senTempHumi); 00073 gSimpleTimer.setInterval(3000, sendLight); 00074 gSimpleTimer.setInterval(4000, sendCH4); 00075 gSimpleTimer.setInterval(5000, sendPM25); 00076 #endif 00077 gSimpleTimer.setInterval(1001, updateLight); 00078 gSimpleTimer.setInterval(4002, updateCH4); 00079 gSimpleTimer.setInterval(4001, updateTempHumi); 00080 #ifdef OPEN_PM25 00081 gSimpleTimer.setInterval(3000, PM25); 00082 #endif 00083 gSimpleTimer.setInterval(4000, led_flash); 00084 #ifdef OPEN_OLED 00085 gSimpleTimer.setInterval(2000, update_oled); 00086 #endif 00087 #ifdef OPEN_PM25 00088 PM25_init(); 00089 #endif 00090 wait_ms(2000); 00091 #ifdef OPEN_OLED 00092 oled_init(adaf); 00093 #endif 00094 #ifdef OPEN_BLYNK 00095 /* 00096 * Set ESP8266 baud rate 00097 * 在LPC824上,波特率设为115200时,ESP8266无法工作 00098 */ 00099 #define TARGET_BAUD 9600 00100 EspSerial.baud(115200); 00101 wifi.setUart(TARGET_BAUD, 2); 00102 EspSerial.baud(TARGET_BAUD); 00103 wait(2.0); 00104 00105 Blynk.begin(auth, wifi, SSID, PASS); 00106 wait(3.0); 00107 #endif 00108 g_Ticker.detach(); 00109 00110 while(1) { 00111 //pc.printf("Enter while(1)\r\n"); 00112 //myled = !myled; 00113 gSimpleTimer.run(); 00114 #ifdef OPEN_BLYNK 00115 Blynk.run(); // All the Blynk Magic happens here... 00116 #endif 00117 00118 } 00119 }
Generated on Tue Jul 12 2022 13:01:30 by
1.7.2