finish ^o^

Dependencies:   Air_Quality DHT SDFileSystem Servo WIZnetInterface httpServer mbed-src

Fork of httpServer-WIZwiki-W7500 by WIZnet

Revision:
20:3b473e577885
Parent:
19:e2b03f4e2c7e
--- a/main.cpp	Wed Aug 19 16:28:07 2015 +0000
+++ b/main.cpp	Fri Aug 21 05:13:49 2015 +0000
@@ -13,17 +13,20 @@
 extern int lumi_val;
 extern int cel_val;
 extern int touch_val;
+extern int control;
 
-DHT sensor(D4, DHT11);
-InterruptIn motion(D5);
+DHT sensor(D8, DHT11);
+InterruptIn motion(D9);
 AnalogIn luminance(A1);
-InterruptIn event(D2);  // touch
+InterruptIn event(D10);  // touch
 Servo myservo(D14);  // touch servo 
 
 DigitalOut led_R(LED1);
 DigitalOut led_G(LED2);
 DigitalOut led_B(LED3);
 
+DigitalOut vol_in(A5);
+
 #ifdef TARGET_WIZWIKI_W7500
     //Choose one of file system.
     SDFileSystem local(SD_MOSI, SD_MISO, SD_CLK, SD_SEL, "local");//PB_3, PB_2, PB_1, PB_0
@@ -71,14 +74,76 @@
     else
     i=0;
 }
+
+void sensor_5() {
+        
+        int rd_sensor = 0;  // when rd_sensor = 0, sensor is ready to read the data.
+        float hum = 0.0f;
+        float cel = 0.0f;
+        vol_in = 0;
+    
+        //DHT sensor
+        rd_sensor = sensor.readData();
+        if (0 == rd_sensor) {
+            hum = sensor.ReadHumidity();
+            cel = sensor.ReadTemperature(CELCIUS);
+            
+            printf("1. Humidity : %4.2f\r\n\n", hum);
+            wait(0.3);
+            printf("2. Temperature in Celcius : %2.2f\r\n\n", cel);
+            wait(0.3); }
+        else
+            printf("1,2. Error! : %d\r\n\n", rd_sensor);
+        
+        // motion    
+        if(motion_detected) {
+            motion_detected = 0;
+
+            printf("3. Something move!\r\n\r\n");
+            wait(0.3);
+            }
+        
+        // luminance    
+        printf("4. Luminance: %f\r\n\r\n", luminance.read());
+        //printf(" + lumi_val = %d\r\n\r\n", lumi_val);
+        
+        if(lumi_val == 0) {
+            led_R=1; led_G=1; led_B=1;} // led off
+        
+        else {     
+            if(luminance.read()<=0.1){
+                led_R=0; led_G=0; led_B=0;} // white LED on
+        
+            else if(0.1<=luminance.read()&&luminance.read()<=0.3){
+                led_R=0; led_G=0; led_B=1;} // yellow LED on
+            
+            else{
+                led_R=1; led_G=1; led_B=1;} // led off
+        }
+        
+        if(control == 1) {
+            if(cel_val == 0)
+                vol_in = 0;
+            else if(cel_val == 1)
+                vol_in = 1; }
+        else {
+            if(cel < 34)
+                vol_in = 0;
+            else if(cel >= 34)
+                vol_in = 1; }
+            
+
+        wait(1);
+}
+
  
  
 int main()
-{
+{    /*
     int rd_sensor = 0;  // when rd_sensor = 0, sensor is ready to read the data.
     float hum = 0.0f;
-    float cel = 0.0f;
-    
+    float cel = 0.0f;  */
+     
     HTTPFsRequestHandler::mount("/local/", "/");
     svr.addHandler<HTTPFsRequestHandler>("/");
  
@@ -122,9 +187,16 @@
     
     while(1) {
         svr.poll();
+        sensor_5();
         
-        wait(0.3);
+        if(control == 0) {
+            while (1)
+                sensor_5();
+        }
+        wait(1);
         
+    
+        /*
         //DHT sensor
         rd_sensor = sensor.readData();
         if (0 == rd_sensor) {
@@ -163,7 +235,7 @@
             
             else{
                 led_R=1; led_G=1; led_B=1;} // led off
-        }   
-        wait(1);
+        }  */ 
+        //wait(1);
     }
 }
\ No newline at end of file