this program is compiled several times with various inputs ..... but at the last we got what we wanted... for any queries mail me at siva4cva@gmail.com use the ''tera term'' terminal for viewing output.

Dependencies:   mbed

Revision:
0:c63035081869
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Dec 23 10:16:49 2015 +0000
@@ -0,0 +1,104 @@
+#include "mbed.h"
+DigitalIn PIR(D8);
+DigitalIn light_sen(D7);
+AnalogIn ADC_CHSEL(A0);
+DigitalOut led(LED1);
+unsigned int ADC_VALUE,Factor;
+float current = 0;
+int wattage;
+float y,meas,a[10],avg;
+int i,x;
+int PIR_sensor;
+int light;
+
+int main() {
+    
+    
+     printf("\n GSAS Micro Systems \n");
+     
+     wait(0.1f);
+ 
+    while(1) {
+        
+        meas = ADC_CHSEL.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
+       
+           avg=0;
+  for(i=0;i<10;i++)
+{
+  a[i]=meas;
+  wait(0.2);
+}
+meas=a[0];
+  for(i=1;i<10;i++){
+      if(meas<a[i])
+           meas=a[i];
+  }
+
+            
+        printf(" actual value = %f\r\n", meas);
+       
+        x = meas*300;
+         avg=0;
+  for(i=0;i<10;i++)
+{
+  a[i]=x;
+  wait(0.2);
+}
+  for(i=0;i<10;i++)
+{
+  avg=avg+(a[i]/10);
+
+            }
+        
+        printf("initial read = %d\r\n", x);
+       
+        meas = x * 1.51; // Change the value to be in the 0 to 3300 range
+          avg=0;
+  for(i=0;i<10;i++)
+{
+  a[i]=meas;
+  wait(0.2);
+}
+  for(i=0;i<10;i++)
+{
+  avg=avg+(a[i]/10);
+
+            }
+        current = (meas - 329.18)/13.59;
+     //   if (current < 0)
+       // {
+         //   current = 0;
+           // }
+        wattage = current * 230;
+        printf("measure = %.2f mV\r\n", meas);
+        printf("current = %.2f A\r\n", current);
+        printf("wattage = %d W\r\n", wattage);
+        
+        printf("======================\r\n");
+          int PIR_sensor;
+    
+        PIR_sensor = PIR;
+        //printf("PIR Value : %d\r\n",PIR_sensor);
+        
+        if (PIR_sensor==1)
+        {
+            printf("==================================== WELCOME ============\r\n");
+            }
+            else
+            printf("=== room is empty ===\r\n");
+            
+            int light;
+            light = light_sen;
+            if (light == 1)
+            {
+            printf("*********************************** light is ON ****************");
+            }
+            else
+            printf("################################### light is OFF ################");
+            
+        
+    
+        
+        wait(0.1); // 200 ms
+    }
+}
\ No newline at end of file