![](/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
main.cpp@0:e674a8b2b330, 2013-05-16 (annotated)
- Committer:
- ngoldin
- Date:
- Thu May 16 12:13:17 2013 +0000
- Revision:
- 0:e674a8b2b330
- Child:
- 1:af0aa8d6e586
first
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ngoldin | 0:e674a8b2b330 | 1 | #include "mbed.h" |
ngoldin | 0:e674a8b2b330 | 2 | #include "m3pi_ng.h" |
ngoldin | 0:e674a8b2b330 | 3 | |
ngoldin | 0:e674a8b2b330 | 4 | |
ngoldin | 0:e674a8b2b330 | 5 | m3pi m3pi; |
ngoldin | 0:e674a8b2b330 | 6 | |
ngoldin | 0:e674a8b2b330 | 7 | DigitalOut mbed_led[] = {(LED1), (LED2),(LED3), (LED4)}; |
ngoldin | 0:e674a8b2b330 | 8 | DigitalOut m3pi_led[] = {(p13), (p14), (p15), (p16), (p17), (p18), (p19), (p20)}; |
ngoldin | 0:e674a8b2b330 | 9 | DigitalIn m3pi_pb(p21); |
ngoldin | 0:e674a8b2b330 | 10 | Timer t1; |
ngoldin | 0:e674a8b2b330 | 11 | Serial btbee(p28, p27); // tx rx |
ngoldin | 0:e674a8b2b330 | 12 | DigitalOut btbee_reset(p26); // 0 resets the device |
ngoldin | 0:e674a8b2b330 | 13 | |
ngoldin | 0:e674a8b2b330 | 14 | int main (){ |
ngoldin | 0:e674a8b2b330 | 15 | // initialization stuff //////////////////////////////////////////////////////////////////////////////////////////////////// |
ngoldin | 0:e674a8b2b330 | 16 | m3pi.locate(0,1); |
ngoldin | 0:e674a8b2b330 | 17 | btbee_reset=1; // else it keeps resetting |
ngoldin | 0:e674a8b2b330 | 18 | for (int i = 0; i <4; i++) { |
ngoldin | 0:e674a8b2b330 | 19 | mbed_led[i] = 0; |
ngoldin | 0:e674a8b2b330 | 20 | } |
ngoldin | 0:e674a8b2b330 | 21 | for (int i = 0; i <8; i++) { |
ngoldin | 0:e674a8b2b330 | 22 | m3pi_led[i]=0; |
ngoldin | 0:e674a8b2b330 | 23 | } |
ngoldin | 0:e674a8b2b330 | 24 | m3pi_pb.mode(PullUp); // expected would be 1 when pb is pressed, 0 when not, opposite is the case |
ngoldin | 0:e674a8b2b330 | 25 | btbee.baud(38400); // this is BtBee default for AT commands |
ngoldin | 0:e674a8b2b330 | 26 | //btbee.baud(9600); // this is BtBee default for regular commands |
ngoldin | 0:e674a8b2b330 | 27 | //btbee.format(); // the default should be fine |
ngoldin | 0:e674a8b2b330 | 28 | // end initialization stuff //////////////////////////////////////////////////////////////////////////////////////////////// |
ngoldin | 0:e674a8b2b330 | 29 | |
ngoldin | 0:e674a8b2b330 | 30 | m3pi.printf("ATSWITCH"); |
ngoldin | 0:e674a8b2b330 | 31 | m3pi.locate(0,0); |
ngoldin | 0:e674a8b2b330 | 32 | m3pi.printf("RIGHT???"); |
ngoldin | 0:e674a8b2b330 | 33 | |
ngoldin | 0:e674a8b2b330 | 34 | wait(0.1); |
ngoldin | 0:e674a8b2b330 | 35 | |
ngoldin | 0:e674a8b2b330 | 36 | m3pi_led[0]=1; |
ngoldin | 0:e674a8b2b330 | 37 | |
ngoldin | 0:e674a8b2b330 | 38 | //btbee.printf("at\r\n"); // test command, returns "OK\r\n" |
ngoldin | 0:e674a8b2b330 | 39 | //btbee.printf("at+uart=9600,0,0\r\n"); //default values, returns "OK\r\n" |
ngoldin | 0:e674a8b2b330 | 40 | //btbee.printf("at+uart=115200,0,0\r\n"); //changing the baud rate, returns "OK\r\n" |
ngoldin | 0:e674a8b2b330 | 41 | btbee.printf("at+uart?\r\n"); //asking for the set parameters, replies "+UART:baud,stop,parity\r\n" |
ngoldin | 0:e674a8b2b330 | 42 | |
ngoldin | 0:e674a8b2b330 | 43 | m3pi_led[1]=1; |
ngoldin | 0:e674a8b2b330 | 44 | |
ngoldin | 0:e674a8b2b330 | 45 | char l1[30]; //array for the reply |
ngoldin | 0:e674a8b2b330 | 46 | |
ngoldin | 0:e674a8b2b330 | 47 | while (!btbee.readable()){ //wait for it |
ngoldin | 0:e674a8b2b330 | 48 | mbed_led[0]=!mbed_led[0]; |
ngoldin | 0:e674a8b2b330 | 49 | wait(0.1); |
ngoldin | 0:e674a8b2b330 | 50 | } |
ngoldin | 0:e674a8b2b330 | 51 | |
ngoldin | 0:e674a8b2b330 | 52 | /* |
ngoldin | 0:e674a8b2b330 | 53 | // abandoned. scanf is notorious and using getchar is recommended. i love c. |
ngoldin | 0:e674a8b2b330 | 54 | int num; |
ngoldin | 0:e674a8b2b330 | 55 | num = btbee.scanf("%s/n",l1); |
ngoldin | 0:e674a8b2b330 | 56 | m3pi.printf("%i",num); |
ngoldin | 0:e674a8b2b330 | 57 | */ |
ngoldin | 0:e674a8b2b330 | 58 | |
ngoldin | 0:e674a8b2b330 | 59 | int pos = 0; |
ngoldin | 0:e674a8b2b330 | 60 | while (btbee.readable()){ |
ngoldin | 0:e674a8b2b330 | 61 | l1[pos]=btbee.getc(); |
ngoldin | 0:e674a8b2b330 | 62 | pos++; |
ngoldin | 0:e674a8b2b330 | 63 | } |
ngoldin | 0:e674a8b2b330 | 64 | m3pi_led[2]=1; |
ngoldin | 0:e674a8b2b330 | 65 | |
ngoldin | 0:e674a8b2b330 | 66 | m3pi.cls(); |
ngoldin | 0:e674a8b2b330 | 67 | m3pi.locate(0,0); |
ngoldin | 0:e674a8b2b330 | 68 | if (pos<9){ |
ngoldin | 0:e674a8b2b330 | 69 | m3pi.print(l1,pos); |
ngoldin | 0:e674a8b2b330 | 70 | } |
ngoldin | 0:e674a8b2b330 | 71 | else{ |
ngoldin | 0:e674a8b2b330 | 72 | m3pi.print(l1,8); |
ngoldin | 0:e674a8b2b330 | 73 | m3pi.locate(0,1); |
ngoldin | 0:e674a8b2b330 | 74 | m3pi.print(l1+8,pos-8); |
ngoldin | 0:e674a8b2b330 | 75 | } |
ngoldin | 0:e674a8b2b330 | 76 | m3pi_led[3]=1; |
ngoldin | 0:e674a8b2b330 | 77 | } |
ngoldin | 0:e674a8b2b330 | 78 |