![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
A short test program for all things m3pi and BtBee.
Dependencies: btbee m3pi_ng mbed
Fork of m3pi_btTest by
main.cpp@2:35d1143053d3, 2013-05-14 (annotated)
- Committer:
- ngoldin
- Date:
- Tue May 14 11:05:52 2013 +0000
- Revision:
- 2:35d1143053d3
- Parent:
- 1:c1845f088b5d
- Child:
- 3:545c4c50dc0f
Adapted for fixed library.
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 | 1:c1845f088b5d | 3 | |
ngoldin | 1:c1845f088b5d | 4 | |
ngoldin | 1:c1845f088b5d | 5 | m3pi m3pi; |
ngoldin | 0:546e224d2f88 | 6 | |
ngoldin | 1:c1845f088b5d | 7 | DigitalOut mbed_led[] = {(LED1), (LED2),(LED3), (LED4)}; |
ngoldin | 1:c1845f088b5d | 8 | DigitalOut m3pi_led[] = {(p13), (p14), (p15), (p16), (p17), (p18), (p19), (p20)}; |
ngoldin | 1:c1845f088b5d | 9 | DigitalIn m3pi_pb(p21); |
ngoldin | 1:c1845f088b5d | 10 | Timer t1; |
ngoldin | 2:35d1143053d3 | 11 | Serial btbee(p28, p27); // tx rx |
ngoldin | 2:35d1143053d3 | 12 | DigitalOut btbee_reset(p26); // 0 resets the device |
ngoldin | 2:35d1143053d3 | 13 | |
ngoldin | 1:c1845f088b5d | 14 | //Serial btbee(p27, p28); // tx rx |
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 | 2:35d1143053d3 | 20 | btbee_reset=1; // else it keeps resetting |
ngoldin | 2:35d1143053d3 | 21 | for (int i = 0; i <4; i++) { |
ngoldin | 2:35d1143053d3 | 22 | mbed_led[i] = 0; |
ngoldin | 2:35d1143053d3 | 23 | } |
ngoldin | 2:35d1143053d3 | 24 | for (int i = 0; i <8; i++) { |
ngoldin | 2:35d1143053d3 | 25 | m3pi_led[i]=0; |
ngoldin | 2:35d1143053d3 | 26 | } |
ngoldin | 1:c1845f088b5d | 27 | m3pi_pb.mode(PullUp); // expected would be 1 when pb is pressed, 0 when not, opposite is the case |
ngoldin | 1:c1845f088b5d | 28 | //btbee.baud(38400); // this is BtBee default for AT commands |
ngoldin | 1:c1845f088b5d | 29 | //btbee.baud(9600); // this is BtBee default for regular commands |
ngoldin | 1:c1845f088b5d | 30 | //btbee.format(); // the default should be fine |
ngoldin | 2:35d1143053d3 | 31 | // end initialization stuff //////////////////////////////////////////////////////////////////////////////////////////////// |
ngoldin | 2:35d1143053d3 | 32 | |
ngoldin | 2:35d1143053d3 | 33 | |
ngoldin | 2:35d1143053d3 | 34 | /* 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 | 35 | m3pi.locate(0,1); |
ngoldin | 1:c1845f088b5d | 36 | m3pi.printf("Num %d",123456789); |
ngoldin | 1:c1845f088b5d | 37 | */ |
ngoldin | 1:c1845f088b5d | 38 | //t1.start(); |
ngoldin | 1:c1845f088b5d | 39 | |
ngoldin | 1:c1845f088b5d | 40 | // 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 | 41 | //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 | 42 | //the number of characters in the array |
ngoldin | 1:c1845f088b5d | 43 | //int len=49; |
ngoldin | 1:c1845f088b5d | 44 | //m3pi.playtune(dixie,len); |
ngoldin | 1:c1845f088b5d | 45 | |
ngoldin | 1:c1845f088b5d | 46 | /* |
ngoldin | 1:c1845f088b5d | 47 | t1.stop(); |
ngoldin | 1:c1845f088b5d | 48 | int t=t1.read_ms(); |
ngoldin | 1:c1845f088b5d | 49 | t1.reset(); |
ngoldin | 1:c1845f088b5d | 50 | m3pi.locate(0,0); //cursor on the LCD; x 0-7 y 0-1 |
ngoldin | 1:c1845f088b5d | 51 | m3pi.printf("%d",t); |
ngoldin | 1:c1845f088b5d | 52 | */ |
ngoldin | 1:c1845f088b5d | 53 | |
ngoldin | 2:35d1143053d3 | 54 | /* |
ngoldin | 2:35d1143053d3 | 55 | // tests for the pushbutton |
ngoldin | 2:35d1143053d3 | 56 | while (true){ |
ngoldin | 2:35d1143053d3 | 57 | m3pi_led[0]=!m3pi_pb; |
ngoldin | 0:546e224d2f88 | 58 | } |
ngoldin | 2:35d1143053d3 | 59 | |
ngoldin | 1:c1845f088b5d | 60 | while(m3pi_pb){ |
ngoldin | 1:c1845f088b5d | 61 | m3pi_led[5]=!m3pi_led[5]; |
ngoldin | 1:c1845f088b5d | 62 | wait(0.1); |
ngoldin | 1:c1845f088b5d | 63 | } |
ngoldin | 2:35d1143053d3 | 64 | */ |
ngoldin | 2:35d1143053d3 | 65 | |
ngoldin | 2:35d1143053d3 | 66 | |
ngoldin | 2:35d1143053d3 | 67 | // test what happens if i try to read from serial and nothing is there |
ngoldin | 2:35d1143053d3 | 68 | // result: it blocks and waits for input |
ngoldin | 2:35d1143053d3 | 69 | /* |
ngoldin | 2:35d1143053d3 | 70 | char c = m3pi.getc(); |
ngoldin | 2:35d1143053d3 | 71 | m3pi.locate(0,1); |
ngoldin | 2:35d1143053d3 | 72 | m3pi.printf("%c",c); |
ngoldin | 2:35d1143053d3 | 73 | mbed_led[0]=1; |
ngoldin | 2:35d1143053d3 | 74 | */ |
ngoldin | 2:35d1143053d3 | 75 | |
ngoldin | 2:35d1143053d3 | 76 | ///* |
ngoldin | 2:35d1143053d3 | 77 | int rawsens[5]; |
ngoldin | 2:35d1143053d3 | 78 | int sens1; |
ngoldin | 2:35d1143053d3 | 79 | int t_sig1; |
ngoldin | 2:35d1143053d3 | 80 | float fl; |
ngoldin | 2:35d1143053d3 | 81 | while(true) { |
ngoldin | 2:35d1143053d3 | 82 | t1.start(); |
ngoldin | 2:35d1143053d3 | 83 | m3pi.raw_sensor(rawsens); |
ngoldin | 2:35d1143053d3 | 84 | t_sig1=t1.read_ms(); |
ngoldin | 2:35d1143053d3 | 85 | //wait(0.1); |
ngoldin | 2:35d1143053d3 | 86 | m3pi.cls(); |
ngoldin | 2:35d1143053d3 | 87 | m3pi.locate(0,1); |
ngoldin | 2:35d1143053d3 | 88 | m3pi.printf("%d",rawsens[0]); |
ngoldin | 2:35d1143053d3 | 89 | |
ngoldin | 2:35d1143053d3 | 90 | m3pi.locate(0,0); |
ngoldin | 2:35d1143053d3 | 91 | m3pi.printf("%d",t1.read_ms()); |
ngoldin | 2:35d1143053d3 | 92 | m3pi.locate(5,0); |
ngoldin | 2:35d1143053d3 | 93 | m3pi.printf("%d",t_sig1); |
ngoldin | 2:35d1143053d3 | 94 | t1.stop(); |
ngoldin | 2:35d1143053d3 | 95 | t1.reset(); |
ngoldin | 2:35d1143053d3 | 96 | m3pi_led[0]=!m3pi_led[0]; |
ngoldin | 2:35d1143053d3 | 97 | } |
ngoldin | 2:35d1143053d3 | 98 | //*/ |
ngoldin | 2:35d1143053d3 | 99 | |
ngoldin | 2:35d1143053d3 | 100 | /* |
ngoldin | 1:c1845f088b5d | 101 | int ii=1; |
ngoldin | 2:35d1143053d3 | 102 | int pos=0; |
ngoldin | 1:c1845f088b5d | 103 | while (true) { |
ngoldin | 1:c1845f088b5d | 104 | m3pi_led[0]=1; |
ngoldin | 1:c1845f088b5d | 105 | m3pi_led[1]=0; |
ngoldin | 1:c1845f088b5d | 106 | if (btbee.writeable()) { |
ngoldin | 1:c1845f088b5d | 107 | if (ii==6){btbee.printf("end\n");} |
ngoldin | 1:c1845f088b5d | 108 | else {btbee.printf("Sensor %d. : %d \n",ii,rawsens[ii-1]);} |
ngoldin | 1:c1845f088b5d | 109 | m3pi_led[0]=0; |
ngoldin | 1:c1845f088b5d | 110 | ii++; |
ngoldin | 1:c1845f088b5d | 111 | m3pi.locate(0,0); |
ngoldin | 1:c1845f088b5d | 112 | m3pi.printf("Sent %0.3d",ii); |
ngoldin | 1:c1845f088b5d | 113 | } |
ngoldin | 1:c1845f088b5d | 114 | |
ngoldin | 1:c1845f088b5d | 115 | while (btbee.readable()) { |
ngoldin | 1:c1845f088b5d | 116 | c = btbee.getc(); |
ngoldin | 1:c1845f088b5d | 117 | m3pi.locate(pos,1); |
ngoldin | 1:c1845f088b5d | 118 | m3pi.print(&c,1); |
ngoldin | 1:c1845f088b5d | 119 | pos++; |
ngoldin | 1:c1845f088b5d | 120 | pos=pos%8; |
ngoldin | 2:35d1143053d3 | 121 | |
ngoldin | 1:c1845f088b5d | 122 | } |
ngoldin | 1:c1845f088b5d | 123 | |
ngoldin | 1:c1845f088b5d | 124 | wait(0.5); |
ngoldin | 1:c1845f088b5d | 125 | } |
ngoldin | 1:c1845f088b5d | 126 | */ |
ngoldin | 0:546e224d2f88 | 127 | } |
ngoldin | 1:c1845f088b5d | 128 | |
ngoldin | 1:c1845f088b5d | 129 | |
ngoldin | 1:c1845f088b5d | 130 |