WSN End Device

Dependencies:   mbed

Fork of I2C_HelloWorld_Mbed by mbed official

main.cpp

Committer:
LAvtec818
Date:
2014-06-16
Revision:
1:bc4ec3bf209e
Parent:
0:f76c26307f9a

File content as of revision 1:bc4ec3bf209e:

#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);

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() {

   
    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) {
                                
         sleep();
        // pc.printf("system on idle\n\r");
        //pc.printf("x1 = %d\n",x1);
    }
}