A short test program for all things m3pi and BtBee.
Dependencies: btbee m3pi_ng mbed
Fork of m3pi_btTest by
Diff: main.cpp
- Revision:
- 4:31939848b5ba
- Parent:
- 3:545c4c50dc0f
- Child:
- 5:2e5fd80518c5
--- a/main.cpp Thu May 16 12:09:39 2013 +0000 +++ b/main.cpp Thu May 16 13:36:46 2013 +0000 @@ -8,16 +8,14 @@ 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 btbee.reset(); for (int i = 0; i <4; i++) { mbed_led[i] = 0; @@ -34,116 +32,55 @@ //btbee.format(); // the default should be fine // end initialization stuff //////////////////////////////////////////////////////////////////////////////////////////////// - - /* THIS IS NOT DOCUMENTED??? Where does the m3pi::printf function come from? m3pi is a child of Stream so it must be from there, probably defined using the m3pi::print function... - m3pi.locate(0,1); - m3pi.printf("Num %d",123456789); - */ - //t1.start(); - + // let me play you the song of my people... // V=volume max is 15::O5=octave5::G16=G16th note::R24=rest24th note...a rest is needed between any two note that are the same //char dixie[]= {'V','1','5','O','5','G','1','6','E','1','6','C','8','R','2','4','C','8','R','2','4','C','1','6','D','1','6','E','1','6','F','1','6','G','8','R','2','4','G','8','R','2','4','G','8','E','1','6'}; //the number of characters in the array //int len=49; //m3pi.playtune(dixie,len); - /* - t1.stop(); - int t=t1.read_ms(); - t1.reset(); - m3pi.locate(0,0); //cursor on the LCD; x 0-7 y 0-1 - m3pi.printf("%d",t); - */ - /* - // tests for the pushbutton - while (true){ - m3pi_led[0]=!m3pi_pb; - } - */ - ///* + // 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); } - //*/ - - // test what happens if i try to read from serial and nothing is there - // result: it blocks and waits for input - /* - char c = m3pi.getc(); - m3pi.locate(0,1); - m3pi.printf("%c",c); - mbed_led[0]=1; - */ - - /* - int rawsens[5]; - int sens1; - int t_sig1; - float fl; - while(true) { - t1.start(); - m3pi.raw_sensor(rawsens); - t_sig1=t1.read_ms(); - //wait(0.1); - m3pi.cls(); - m3pi.locate(0,1); - m3pi.printf("%d",rawsens[0]); - - m3pi.locate(0,0); - m3pi.printf("%d",t1.read_ms()); - m3pi.locate(5,0); - m3pi.printf("%d",t_sig1); - t1.stop(); - t1.reset(); - m3pi_led[0]=!m3pi_led[0]; - } - */ - - ///* - int ii=1; - int pos=0; - int write = 1; - char c; - char arr_read[30]; - int chars_read; + int iline=1; + int write = 1; // this could also be a boolean + 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) { - m3pi_led[0]=1; - m3pi_led[1]=0; + + // this writes "Line 001\n" to "Line 005\n" and then "end\n" to the btbee if (btbee.writeable() && write ) { - if (ii==6) { + if (iline==6) { btbee.printf("end\n"); write=1; - } - //else {btbee.printf("Sensor %d. : %d \n",ii,rawsens[ii-1]);} + }//if else { - btbee.printf("Line %0.3d \n",ii); + btbee.printf("Line %0.3d \n",iline); m3pi_led[0]=0; m3pi.locate(0,0); - m3pi.printf("Sent %0.3d",ii); - ii++; - } - } + m3pi.printf("Sent %0.3d",iline); + iline++; + }//else + }//if_write + + // check for answers after each write /not write while (btbee.readable()) { - //c = btbee.getc(); - //m3pi.locate(pos,1); - //m3pi.print(&c,1); - //pos++; - //pos=pos%8; 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; - } - pos=0; + }//while_readable wait(0.1); - } - //*/ -} + }//while true + +}//main