works with masterboard.

main.cpp

Committer:
zenglingxuan
Date:
2013-05-03
Revision:
0:838bb871a4d1

File content as of revision 0:838bb871a4d1:

#include "mbed.h"

Serial xbee1(PTC4, PTC3);       //xbee
DigitalOut rst1(PTC5);

AnalogIn dis(PTB0);     //range finder
DigitalOut myled(LED1);

int main() {
       
        int per;        //range per
        char f;         //range flag
        int l;          //led indicator

        
        // reset the xbees (at least 200ns)
        rst1 = 0;
        wait_ms(1); 
        rst1 = 1;
        wait_ms(1);    
    
    
    while(1) {
        //cal distance and set flag when close enough
        per=dis*512/3.3;
        if (per<3){
        f='1';
        l=0;
        }
        else {
        f='0';
        l=1;
        }
        myled=l;
        
        xbee1.putc(f);
        
        wait(1); 
    }
}