work.

Dependencies:   Blynk mbed

Revision:
2:6cd3b0947188
Parent:
1:0e75de2a5d21
Child:
3:4cd9171ba989
--- a/main.cpp	Mon Jun 13 02:21:11 2016 +0000
+++ b/main.cpp	Wed Jun 15 03:08:40 2016 +0000
@@ -1,23 +1,46 @@
 #include "mbed.h"
 
+#include "MicroduinoPinNames.h"
+DigitalOut myled(P0_20);
+I2C g_i2c(P0_11, P0_10);//SDA, SCL
+#if 1
+#include "SimpleTimer.h"
 #include "userDef.h"
 #include "sensor.h"
 #include "oled.h"
+#endif
 //#include "WiFiBlynk.h"
-//#include "Adafruit_SSD1306.h"
+
+//Serial pc(P0_4, P0_0); // tx, rx
+
+Timer g_Timer;
 
-//Serial           pc(D1, D0); // tx, rx
-DigitalOut myled(P0_13);
-Timer g_Timer;
-//I2C g_i2c(P0_11, P0_10);//SDA, SCL
-//Adafruit_SSD1306_I2c adaf(g_i2c, P0_13, 0x78, 64, 128);
+void led_flash()
+{
+    static int count = 0;
+    count++;
+    //pc.printf("count : %d, ms : %d\r\n", count, g_Timer.read_ms());
+    //myled = 1;
+    wait_ms(70);
+    myled = 0;
+}
+
+Adafruit_SSD1306_I2c adaf(g_i2c, P0_13, 0x78, 64, 128);
+void update_oled()
+{
+    myled = 1;
+    wait_ms(70);
+    myled = 0;
+    oled(adaf, sensor_tem, sensor_hum, sensor_light, sensorPM25, Sensor_etoh);
+}
+
 int main()
 {
-    //pc.baud(115200);
-    //myled = 0;
-    int ms = 0;
+    //pc.baud(9600);
+    //myled = 1;
     g_Timer.start();
-    //U8GLIB_SSD1306_MICRODUINO_128X64 u8glibhehe(U8G_I2C_OPT_NONE);     //设置OLED型号
+    SimpleTimer gSimpleTimer(g_Timer);
+    
     //Serial.begin(9600); // See the connection status in Serial Monitor
     // Set ESP8266 baud rate
     //EspSerial.begin(115200);
@@ -25,74 +48,31 @@
     //Blynk.begin(auth, wifi, SSID, PASS);
 
     // Setup a function to be called every second
-    //temHumtimer.setInterval(2000L, senTempHumi);
-    wait_ms(1000);
-    //Adafruit_SSD1306_I2c adaf(g_i2c, P0_13, 0x78, 64, 128);
-    //Adafruit_SSD1306_I2c adaf(g_i2c, P0_13);
+    //gSimpleTimer.setInterval(2000L, senTempHumi);
+    gSimpleTimer.setInterval(1000, updateLight);
+    gSimpleTimer.setInterval(5000, updateCH4);
+    gSimpleTimer.setInterval(4000, updateTempHumi);
+    //gSimpleTimer.setInterval(3000, PM25);
+    //gSimpleTimer.setInterval(4000, led_flash);
+    gSimpleTimer.setInterval(1000, update_oled);
+    
+    //PM25_init();
     wait_ms(2000);
-    //u8glibhehe.init_u8g();
-    oled_init();
+    oled_init(adaf);
+    int pretime = g_Timer.read_ms();
     while(1) {
-        //printf("Enter while(1)\r\n");
-        myled = !myled;
+        //pc.printf("Enter while(1)\r\n");
+        //myled = !myled;
         //Blynk.run(); // All the Blynk Magic happens here...
-        //temHumtimer.run(); // Initiates SimpleTimer
-
-        //updateTempHumi();
-        //updateLight();
-        //updateCH4();
-
-        ms = g_Timer.read_ms();
-        #if 1
-        if (pm25_time > ms) pm25_time = ms;
-        if (ms - pm25_time > INTERVAL_pm25) {
-            //sensorPM25 = PM25();
-            pm25_time = ms;    //更新计时器
+        gSimpleTimer.run();
+        #if 0
+        int curtime = g_Timer.read_ms();
+        if (curtime - pretime > 4000) {
+            //updateTempHumi();
+            led_flash();
+            pretime = curtime;
         }
         #endif
-        #if 0
-        adaf.clearDisplay();
-        adaf.drawRect(1, 1, 30,30, WHITE);
-        adaf.display();
-        #endif
-        //drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
-        //oled(u8glibhehe, sensor_tem, sensor_hum, sensor_light, sensorPM25, Sensor_etoh);
-        oled(sensor_tem, sensor_hum, sensor_light, sensorPM25, Sensor_etoh);
-        wait(0.1);
         
     }
 }
-
-/** Write to an I2C slave
-     *
-     * Performs a complete write transaction. The bottom bit of
-     * the address is forced to 0 to indicate a write.
-     *
-     *  @param address 8-bit I2C slave address [ addr | 0 ]
-     *  @param data Pointer to the byte-array data to send
-     *  @param length Number of bytes to send
-     *  @param repeated Repeated start, true - do not send stop at end
-     *
-     *  @returns
-     *       0 on success (ack),
-     *   non-0 on failure (nack)
-     */
-int i2c_write1(int address, const char *data, int length)
-{
-    //return g_i2c.write(address, data, length);
-}
-
-void log(char *s)
-{
-    printf("%s\r\n", s);
-}
-
-void open_led(void)
-{
-    //myled = 1;
-}
-
-void close_led(void)
-{
-    //myled = 0;
-}