Resident Community management

Dependencies:   HCSR04 Servo mbed

Revision:
1:054435f5db1c
Parent:
0:2d3a72735265
diff -r 2d3a72735265 -r 054435f5db1c main.cpp
--- a/main.cpp	Tue Sep 18 03:17:27 2018 +0000
+++ b/main.cpp	Thu Sep 20 08:22:34 2018 +0000
@@ -3,8 +3,11 @@
 #include "Servo.h"
 
 DigitalIn PIR(D4);
+DigitalOut LED(D10);
 AnalogIn LDR(A0);
 AnalogIn Gas(A1);
+InterruptIn button1(D8);
+InterruptIn button2(D6);
 
 
 Serial pc(USBTX,USBRX);
@@ -16,12 +19,29 @@
 HCSR04 ultrasonic(D9,D7); //trigger,echo
 Servo servo(D14);
 
+
+void open()
+{   
+pc.printf("open");
+    servo.position(180);
+    }
+    
+
+void close()
+{   
+pc.printf("close");
+    servo.position(0);
+    }    
+
 int main()
 {
     pc.baud(9600);
     esp_serial.baud(115200);
     pc.printf("begin");
     
+    button1.rise(&open);
+    button2.rise(&close);
+    
     while(1) {
         
         val = PIR.read();
@@ -34,7 +54,7 @@
             esp_serial.printf("%d",dist);
             esp_serial.putc('\0');
 
-            if (dist>5.0) {
+            if (dist>10.0) {
                 servo.position(180);
                 wait(5);
                 servo.position(0);
@@ -53,7 +73,12 @@
         esp_serial.printf("L");
         esp_serial.printf("%d",ldr_val);
         esp_serial.putc('\0');
-        wait(5);
+        if(ldr_val <=300)
+        LED = 1;
+        
+        else 
+        LED = 0;
+        wait(2);
         
         
         gas_val = Gas.read_u16();
@@ -61,5 +86,8 @@
         esp_serial.printf("G");
         esp_serial.printf("%d",gas_val);
         esp_serial.putc('\0');
+        //wait(10);
         }
-    }
\ No newline at end of file
+    }
+    
+