This was made by Niko for bluetooth communication
Dependencies: m3pi_ng
main.cpp
- Committer:
- satyson
- Date:
- 2014-05-22
- Revision:
- 0:e6896e4f41d0
File content as of revision 0:e6896e4f41d0:
#include "mbed.h" #include "m3pi_ng.h" #include "btbee.h" // Made by Niko m3pi m3pi; btbee btbee; DigitalOut mbed_led[] = {(LED1), (LED2),(LED3), (LED4)}; DigitalOut m3pi_led[] = {(p13), (p14), (p15), (p16), (p17), (p18), (p19), (p20)}; DigitalIn m3pi_pb(p21); int main() { // initialization stuff //////////////////////////////////////////////////////////////////////////////////////////////////// m3pi.locate(0,1); btbee.reset(); for (int i = 0; i <4; i++) { mbed_led[i] = 0; } for (int i = 0; i <8; i++) { m3pi_led[i]=0; } m3pi_pb.mode(PullUp); // expected would be 1 when pb is pressed, 0 when not, opposite is the case // end initialization stuff //////////////////////////////////////////////////////////////////////////////////////////////// m3pi.locate(0,0); m3pi.printf("B:%0.3f%V",m3pi.battery()); wait(0.3); m3pi.locate(0,0); m3pi.printf("%s","btTest"); m3pi.locate(0,1); m3pi.printf("%s","PBonLNK"); // wait for the user to push P21, should be pressed when the bt link is established (green led "link") while(m3pi_pb) { m3pi_led[0]=!m3pi_led[0]; wait(0.1); } int iline=1; char arr_read[30]; // this should be long enough to store any reply coming in over bt. int chars_read; // number of chars read in a bt reply while (true) { // this writes "Line 001\n" to "Line 005\n" and then "end\n" to the btbee if ( btbee.writeable() ) { if (iline==6) { btbee.printf("end\n"); iline++; }//if else { if (iline <6){ btbee.printf("Line %0.3d \n",iline); m3pi_led[0]=0; m3pi.locate(0,0); m3pi.printf("Sent %0.3d",iline); iline++; } }//else }//if_write // check for answers after each write /not write while ( btbee.readable() ) { m3pi_led[7]=1; btbee.read_all(arr_read, 30, &chars_read ); m3pi_led[6]=1; m3pi.locate(0,1); m3pi.print(arr_read,chars_read); m3pi_led[5]=1; }//while_readable wait(0.1); }//while_true }//main