A short test program for all things m3pi and BtBee.
Dependencies: btbee m3pi_ng mbed
Fork of m3pi_btTest by
main.cpp@3:545c4c50dc0f, 2013-05-16 (annotated)
- Committer:
- ngoldin
- Date:
- Thu May 16 12:09:39 2013 +0000
- Revision:
- 3:545c4c50dc0f
- Parent:
- 2:35d1143053d3
- Child:
- 4:31939848b5ba
bla
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ngoldin | 0:546e224d2f88 | 1 | #include "mbed.h" |
ngoldin | 1:c1845f088b5d | 2 | #include "m3pi_ng.h" |
ngoldin | 3:545c4c50dc0f | 3 | #include "btbee.h" |
ngoldin | 1:c1845f088b5d | 4 | |
ngoldin | 1:c1845f088b5d | 5 | m3pi m3pi; |
ngoldin | 3:545c4c50dc0f | 6 | btbee btbee; |
ngoldin | 0:546e224d2f88 | 7 | |
ngoldin | 1:c1845f088b5d | 8 | DigitalOut mbed_led[] = {(LED1), (LED2),(LED3), (LED4)}; |
ngoldin | 1:c1845f088b5d | 9 | DigitalOut m3pi_led[] = {(p13), (p14), (p15), (p16), (p17), (p18), (p19), (p20)}; |
ngoldin | 1:c1845f088b5d | 10 | DigitalIn m3pi_pb(p21); |
ngoldin | 1:c1845f088b5d | 11 | Timer t1; |
ngoldin | 3:545c4c50dc0f | 12 | //Serial btbee(p28, p27); // tx rx |
ngoldin | 3:545c4c50dc0f | 13 | //DigitalOut btbee_reset(p26); // 0 resets the device |
ngoldin | 2:35d1143053d3 | 14 | |
ngoldin | 2:35d1143053d3 | 15 | |
ngoldin | 1:c1845f088b5d | 16 | int main() |
ngoldin | 1:c1845f088b5d | 17 | { |
ngoldin | 2:35d1143053d3 | 18 | // initialization stuff //////////////////////////////////////////////////////////////////////////////////////////////////// |
ngoldin | 1:c1845f088b5d | 19 | m3pi.locate(0,1); |
ngoldin | 3:545c4c50dc0f | 20 | //btbee_reset=1; // else it keeps resetting |
ngoldin | 3:545c4c50dc0f | 21 | btbee.reset(); |
ngoldin | 2:35d1143053d3 | 22 | for (int i = 0; i <4; i++) { |
ngoldin | 2:35d1143053d3 | 23 | mbed_led[i] = 0; |
ngoldin | 2:35d1143053d3 | 24 | } |
ngoldin | 2:35d1143053d3 | 25 | for (int i = 0; i <8; i++) { |
ngoldin | 2:35d1143053d3 | 26 | m3pi_led[i]=0; |
ngoldin | 2:35d1143053d3 | 27 | } |
ngoldin | 1:c1845f088b5d | 28 | m3pi_pb.mode(PullUp); // expected would be 1 when pb is pressed, 0 when not, opposite is the case |
ngoldin | 3:545c4c50dc0f | 29 | // NOTE on baud rate: the baud rate to be used has to be set on the btBee beforehand. this uses the at mode which is activated by hardware switch. |
ngoldin | 3:545c4c50dc0f | 30 | // only use the hw switch while powered off. use the configure_btbee program to write to it. |
ngoldin | 3:545c4c50dc0f | 31 | |
ngoldin | 1:c1845f088b5d | 32 | //btbee.baud(9600); // this is BtBee default for regular commands |
ngoldin | 3:545c4c50dc0f | 33 | btbee.baud(115200); // this is BtBee regular command set baud rate |
ngoldin | 1:c1845f088b5d | 34 | //btbee.format(); // the default should be fine |
ngoldin | 3:545c4c50dc0f | 35 | // end initialization stuff //////////////////////////////////////////////////////////////////////////////////////////////// |
ngoldin | 2:35d1143053d3 | 36 | |
ngoldin | 2:35d1143053d3 | 37 | |
ngoldin | 2:35d1143053d3 | 38 | /* 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... |
ngoldin | 1:c1845f088b5d | 39 | m3pi.locate(0,1); |
ngoldin | 1:c1845f088b5d | 40 | m3pi.printf("Num %d",123456789); |
ngoldin | 1:c1845f088b5d | 41 | */ |
ngoldin | 1:c1845f088b5d | 42 | //t1.start(); |
ngoldin | 1:c1845f088b5d | 43 | |
ngoldin | 1:c1845f088b5d | 44 | // 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 |
ngoldin | 1:c1845f088b5d | 45 | //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'}; |
ngoldin | 1:c1845f088b5d | 46 | //the number of characters in the array |
ngoldin | 1:c1845f088b5d | 47 | //int len=49; |
ngoldin | 1:c1845f088b5d | 48 | //m3pi.playtune(dixie,len); |
ngoldin | 1:c1845f088b5d | 49 | |
ngoldin | 1:c1845f088b5d | 50 | /* |
ngoldin | 1:c1845f088b5d | 51 | t1.stop(); |
ngoldin | 1:c1845f088b5d | 52 | int t=t1.read_ms(); |
ngoldin | 1:c1845f088b5d | 53 | t1.reset(); |
ngoldin | 1:c1845f088b5d | 54 | m3pi.locate(0,0); //cursor on the LCD; x 0-7 y 0-1 |
ngoldin | 1:c1845f088b5d | 55 | m3pi.printf("%d",t); |
ngoldin | 1:c1845f088b5d | 56 | */ |
ngoldin | 1:c1845f088b5d | 57 | |
ngoldin | 2:35d1143053d3 | 58 | /* |
ngoldin | 2:35d1143053d3 | 59 | // tests for the pushbutton |
ngoldin | 2:35d1143053d3 | 60 | while (true){ |
ngoldin | 2:35d1143053d3 | 61 | m3pi_led[0]=!m3pi_pb; |
ngoldin | 0:546e224d2f88 | 62 | } |
ngoldin | 3:545c4c50dc0f | 63 | */ |
ngoldin | 3:545c4c50dc0f | 64 | ///* |
ngoldin | 3:545c4c50dc0f | 65 | while(m3pi_pb) { |
ngoldin | 3:545c4c50dc0f | 66 | m3pi_led[0]=!m3pi_led[0]; |
ngoldin | 3:545c4c50dc0f | 67 | wait(0.1); |
ngoldin | 1:c1845f088b5d | 68 | } |
ngoldin | 3:545c4c50dc0f | 69 | //*/ |
ngoldin | 2:35d1143053d3 | 70 | |
ngoldin | 2:35d1143053d3 | 71 | |
ngoldin | 2:35d1143053d3 | 72 | // test what happens if i try to read from serial and nothing is there |
ngoldin | 2:35d1143053d3 | 73 | // result: it blocks and waits for input |
ngoldin | 2:35d1143053d3 | 74 | /* |
ngoldin | 2:35d1143053d3 | 75 | char c = m3pi.getc(); |
ngoldin | 2:35d1143053d3 | 76 | m3pi.locate(0,1); |
ngoldin | 2:35d1143053d3 | 77 | m3pi.printf("%c",c); |
ngoldin | 2:35d1143053d3 | 78 | mbed_led[0]=1; |
ngoldin | 2:35d1143053d3 | 79 | */ |
ngoldin | 2:35d1143053d3 | 80 | |
ngoldin | 3:545c4c50dc0f | 81 | /* |
ngoldin | 2:35d1143053d3 | 82 | int rawsens[5]; |
ngoldin | 2:35d1143053d3 | 83 | int sens1; |
ngoldin | 2:35d1143053d3 | 84 | int t_sig1; |
ngoldin | 2:35d1143053d3 | 85 | float fl; |
ngoldin | 2:35d1143053d3 | 86 | while(true) { |
ngoldin | 2:35d1143053d3 | 87 | t1.start(); |
ngoldin | 3:545c4c50dc0f | 88 | m3pi.raw_sensor(rawsens); |
ngoldin | 2:35d1143053d3 | 89 | t_sig1=t1.read_ms(); |
ngoldin | 2:35d1143053d3 | 90 | //wait(0.1); |
ngoldin | 2:35d1143053d3 | 91 | m3pi.cls(); |
ngoldin | 2:35d1143053d3 | 92 | m3pi.locate(0,1); |
ngoldin | 2:35d1143053d3 | 93 | m3pi.printf("%d",rawsens[0]); |
ngoldin | 2:35d1143053d3 | 94 | |
ngoldin | 2:35d1143053d3 | 95 | m3pi.locate(0,0); |
ngoldin | 2:35d1143053d3 | 96 | m3pi.printf("%d",t1.read_ms()); |
ngoldin | 2:35d1143053d3 | 97 | m3pi.locate(5,0); |
ngoldin | 2:35d1143053d3 | 98 | m3pi.printf("%d",t_sig1); |
ngoldin | 2:35d1143053d3 | 99 | t1.stop(); |
ngoldin | 2:35d1143053d3 | 100 | t1.reset(); |
ngoldin | 2:35d1143053d3 | 101 | m3pi_led[0]=!m3pi_led[0]; |
ngoldin | 2:35d1143053d3 | 102 | } |
ngoldin | 3:545c4c50dc0f | 103 | */ |
ngoldin | 2:35d1143053d3 | 104 | |
ngoldin | 3:545c4c50dc0f | 105 | ///* |
ngoldin | 1:c1845f088b5d | 106 | int ii=1; |
ngoldin | 2:35d1143053d3 | 107 | int pos=0; |
ngoldin | 3:545c4c50dc0f | 108 | int write = 1; |
ngoldin | 3:545c4c50dc0f | 109 | char c; |
ngoldin | 3:545c4c50dc0f | 110 | char arr_read[30]; |
ngoldin | 3:545c4c50dc0f | 111 | int chars_read; |
ngoldin | 1:c1845f088b5d | 112 | while (true) { |
ngoldin | 1:c1845f088b5d | 113 | m3pi_led[0]=1; |
ngoldin | 1:c1845f088b5d | 114 | m3pi_led[1]=0; |
ngoldin | 3:545c4c50dc0f | 115 | if (btbee.writeable() && write ) { |
ngoldin | 3:545c4c50dc0f | 116 | if (ii==6) { |
ngoldin | 3:545c4c50dc0f | 117 | btbee.printf("end\n"); |
ngoldin | 3:545c4c50dc0f | 118 | write=1; |
ngoldin | 3:545c4c50dc0f | 119 | } |
ngoldin | 3:545c4c50dc0f | 120 | //else {btbee.printf("Sensor %d. : %d \n",ii,rawsens[ii-1]);} |
ngoldin | 3:545c4c50dc0f | 121 | else { |
ngoldin | 3:545c4c50dc0f | 122 | btbee.printf("Line %0.3d \n",ii); |
ngoldin | 3:545c4c50dc0f | 123 | m3pi_led[0]=0; |
ngoldin | 3:545c4c50dc0f | 124 | m3pi.locate(0,0); |
ngoldin | 3:545c4c50dc0f | 125 | m3pi.printf("Sent %0.3d",ii); |
ngoldin | 3:545c4c50dc0f | 126 | ii++; |
ngoldin | 3:545c4c50dc0f | 127 | } |
ngoldin | 1:c1845f088b5d | 128 | } |
ngoldin | 1:c1845f088b5d | 129 | while (btbee.readable()) { |
ngoldin | 3:545c4c50dc0f | 130 | //c = btbee.getc(); |
ngoldin | 3:545c4c50dc0f | 131 | //m3pi.locate(pos,1); |
ngoldin | 3:545c4c50dc0f | 132 | //m3pi.print(&c,1); |
ngoldin | 3:545c4c50dc0f | 133 | //pos++; |
ngoldin | 3:545c4c50dc0f | 134 | //pos=pos%8; |
ngoldin | 3:545c4c50dc0f | 135 | m3pi_led[7]=1; |
ngoldin | 3:545c4c50dc0f | 136 | btbee.read_all(arr_read, 30, &chars_read ); |
ngoldin | 3:545c4c50dc0f | 137 | m3pi_led[6]=1; |
ngoldin | 3:545c4c50dc0f | 138 | m3pi.locate(0,1); |
ngoldin | 3:545c4c50dc0f | 139 | m3pi.print(arr_read,chars_read); |
ngoldin | 3:545c4c50dc0f | 140 | m3pi_led[5]=1; |
ngoldin | 1:c1845f088b5d | 141 | } |
ngoldin | 3:545c4c50dc0f | 142 | pos=0; |
ngoldin | 3:545c4c50dc0f | 143 | wait(0.1); |
ngoldin | 1:c1845f088b5d | 144 | } |
ngoldin | 3:545c4c50dc0f | 145 | //*/ |
ngoldin | 0:546e224d2f88 | 146 | } |
ngoldin | 1:c1845f088b5d | 147 | |
ngoldin | 1:c1845f088b5d | 148 | |
ngoldin | 1:c1845f088b5d | 149 |