![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Nikolas Goldin original creater of this. Added some of my own notes and also a few additional commands
Dependencies: btbee m3pi_ng mbed
Fork of configure_btbee by
Diff: main.cpp
- Revision:
- 0:e674a8b2b330
- Child:
- 1:af0aa8d6e586
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu May 16 12:13:17 2013 +0000 @@ -0,0 +1,78 @@ +#include "mbed.h" +#include "m3pi_ng.h" + + +m3pi m3pi; + +DigitalOut mbed_led[] = {(LED1), (LED2),(LED3), (LED4)}; +DigitalOut m3pi_led[] = {(p13), (p14), (p15), (p16), (p17), (p18), (p19), (p20)}; +DigitalIn m3pi_pb(p21); +Timer t1; +Serial btbee(p28, p27); // tx rx +DigitalOut btbee_reset(p26); // 0 resets the device + +int main (){ + // initialization stuff //////////////////////////////////////////////////////////////////////////////////////////////////// + m3pi.locate(0,1); + btbee_reset=1; // else it keeps resetting + 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 + btbee.baud(38400); // this is BtBee default for AT commands + //btbee.baud(9600); // this is BtBee default for regular commands + //btbee.format(); // the default should be fine + // end initialization stuff //////////////////////////////////////////////////////////////////////////////////////////////// + + m3pi.printf("ATSWITCH"); + m3pi.locate(0,0); + m3pi.printf("RIGHT???"); + + wait(0.1); + + m3pi_led[0]=1; + + //btbee.printf("at\r\n"); // test command, returns "OK\r\n" + //btbee.printf("at+uart=9600,0,0\r\n"); //default values, returns "OK\r\n" + //btbee.printf("at+uart=115200,0,0\r\n"); //changing the baud rate, returns "OK\r\n" + btbee.printf("at+uart?\r\n"); //asking for the set parameters, replies "+UART:baud,stop,parity\r\n" + + m3pi_led[1]=1; + + char l1[30]; //array for the reply + + while (!btbee.readable()){ //wait for it + mbed_led[0]=!mbed_led[0]; + wait(0.1); + } + + /* + // abandoned. scanf is notorious and using getchar is recommended. i love c. + int num; + num = btbee.scanf("%s/n",l1); + m3pi.printf("%i",num); + */ + + int pos = 0; + while (btbee.readable()){ + l1[pos]=btbee.getc(); + pos++; + } + m3pi_led[2]=1; + + m3pi.cls(); + m3pi.locate(0,0); + if (pos<9){ + m3pi.print(l1,pos); + } + else{ + m3pi.print(l1,8); + m3pi.locate(0,1); + m3pi.print(l1+8,pos-8); + } + m3pi_led[3]=1; +} +