WSN End Device

Dependencies:   mbed

Fork of I2C_HelloWorld_Mbed by mbed official

Revision:
1:bc4ec3bf209e
Parent:
0:f76c26307f9a
--- a/main.cpp	Thu Feb 14 17:24:48 2013 +0000
+++ b/main.cpp	Mon Jun 16 18:23:01 2014 +0000
@@ -1,25 +1,79 @@
 #include "mbed.h"
+#include "PowerControl.h"
+#include "EthernetPowerControl.h"
  
 // Read temperature from LM75BD
+#define USR_POWERDOWN    (0x104)
 
 I2C i2c(p28, p27);
+Serial pc(USBTX, USBRX); // tx, rx
+InterruptIn PIR_in(p5);
+Serial xbee1(p9,p10);
+DigitalOut rst1(p11);
 
-const int addr = 0x90;
+Timer t;
+
+//Ticker flipper;
+
+const int tx_addr = 0x14;
+const int rx_addr = 0x15;
+char readbuff [35];
+char tx_cmd[1];
+
+void flip() {
+    char c = 'z';
+    tx_cmd[0] = 0x4C;
+        //tx_cmd[1] = 0x4C;
+        //i2c.write(tx_addr,
+        i2c.write(tx_addr, tx_cmd , 1);
+ 
+        wait(0.25);
+ 
+        //i2c.write(rx_addr, cmd, 1);
+        i2c.read(rx_addr, readbuff, 35);
+ 
+        //float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0);
+        int x = 256*readbuff[1] + readbuff [0];
+        
+        //xbee1.printf("%d\t%d\t%d\t%d\n\r%d\t%d\t%d\t%d\n\r%d\t%d\t%d\t%d\n\r%d\t%d\t%d\t%d\n\r\n\r",x1,x2,x3,
+        //x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16);
+        for (int i = 2; i < 34; i++)
+        xbee1.putc(readbuff[i]);
+            
+        int x17 = readbuff[34];    
+}
 
 int main() {
-    char cmd[2];
+
+   
+    i2c.frequency(50000);
+     xbee1.baud(115200);
+     
+     PHY_PowerDown();
+    
+
+    //PHY_PowerDown();
+    rst1 = 0; //Set reset pin to 0
+    wait_ms(1);//Wait at least one millisecond
+    rst1 = 1;//Set reset pin to 1
+    wait_ms(1);
+    
+    wait_ms(75000) ; // wait for 1 minute for initial start up
+    
+    PIR_in.rise(&flip); 
+    PIR_in.fall(&flip);
+    
+  /*  if ((xbee1.readable()){
+        if ('y' == xbee1.getc())
+        break;
+        else 
+          sleep();
+          }*/
+    
     while (1) {
-        cmd[0] = 0x01;
-        cmd[1] = 0x00;
-        i2c.write(addr, cmd, 2);
- 
-        wait(0.5);
- 
-        cmd[0] = 0x00;
-        i2c.write(addr, cmd, 1);
-        i2c.read(addr, cmd, 2);
- 
-        float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0);
-        printf("Temp = %.2f\n", tmp);
+                                
+         sleep();
+        // pc.printf("system on idle\n\r");
+        //pc.printf("x1 = %d\n",x1);
     }
 }
\ No newline at end of file