A short test program for all things m3pi and BtBee.

Dependencies:   btbee m3pi_ng mbed

Fork of m3pi_btTest by Nikolas Goldin

Committer:
ngoldin
Date:
Mon May 13 10:55:33 2013 +0000
Revision:
1:c1845f088b5d
Parent:
0:546e224d2f88
Child:
2:35d1143053d3
first commit

Who changed what in which revision?

UserRevisionLine numberNew 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 1:c1845f088b5d 11 //Serial btbee(p28, p27); // tx rx
ngoldin 1:c1845f088b5d 12 //DigitalOut btbee_reset(p26); // 0 resets the device
ngoldin 1:c1845f088b5d 13 //Serial btbee(p27, p28); // tx rx
ngoldin 1:c1845f088b5d 14 int main()
ngoldin 1:c1845f088b5d 15 {
ngoldin 1:c1845f088b5d 16 m3pi.locate(0,1);
ngoldin 1:c1845f088b5d 17 //btbee_reset=1; // else it keeps resetting
ngoldin 1:c1845f088b5d 18 mbed_led[0] = 1;
ngoldin 1:c1845f088b5d 19 mbed_led[1] = 1;
ngoldin 1:c1845f088b5d 20 mbed_led[2] = 1;
ngoldin 1:c1845f088b5d 21 mbed_led[3] = 1;
ngoldin 1:c1845f088b5d 22 m3pi_pb.mode(PullUp); // expected would be 1 when pb is pressed, 0 when not, opposite is the case
ngoldin 1:c1845f088b5d 23 //btbee.baud(38400); // this is BtBee default for AT commands
ngoldin 1:c1845f088b5d 24 //btbee.baud(9600); // this is BtBee default for regular commands
ngoldin 1:c1845f088b5d 25 //btbee.format(); // the default should be fine
ngoldin 1:c1845f088b5d 26
ngoldin 1:c1845f088b5d 27
ngoldin 1:c1845f088b5d 28 /*
ngoldin 1:c1845f088b5d 29 for (int i = 0; i <8; i++) {
ngoldin 1:c1845f088b5d 30 m3pi_led[i]=1;
ngoldin 1:c1845f088b5d 31 }
ngoldin 1:c1845f088b5d 32 */
ngoldin 1:c1845f088b5d 33
ngoldin 1:c1845f088b5d 34 /* THIS IS NOT DOCUMENTED???
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 wait(1); // 1 second
ngoldin 1:c1845f088b5d 48 mbed_led[0] = 0;
ngoldin 1:c1845f088b5d 49 mbed_led[1] = 0;
ngoldin 1:c1845f088b5d 50 mbed_led[2] = 0;
ngoldin 1:c1845f088b5d 51 mbed_led[3] = 0;
ngoldin 1:c1845f088b5d 52
ngoldin 1:c1845f088b5d 53 for (int i = 0; i <8; i++) {
ngoldin 1:c1845f088b5d 54 m3pi_led[i]=0;
ngoldin 1:c1845f088b5d 55 }
ngoldin 1:c1845f088b5d 56 */
ngoldin 1:c1845f088b5d 57
ngoldin 1:c1845f088b5d 58 /*
ngoldin 1:c1845f088b5d 59 t1.stop();
ngoldin 1:c1845f088b5d 60 int t=t1.read_ms();
ngoldin 1:c1845f088b5d 61 t1.reset();
ngoldin 0:546e224d2f88 62
ngoldin 1:c1845f088b5d 63 m3pi.locate(0,0); //cursor on the LCD; x 0-7 y 0-1
ngoldin 1:c1845f088b5d 64 m3pi.printf("%d",t);
ngoldin 1:c1845f088b5d 65 m3pi.locate(0,1);
ngoldin 1:c1845f088b5d 66 */
ngoldin 1:c1845f088b5d 67
ngoldin 1:c1845f088b5d 68
ngoldin 1:c1845f088b5d 69 //while (true){
ngoldin 1:c1845f088b5d 70 //m3pi_led[0]=!m3pi_pb;
ngoldin 1:c1845f088b5d 71 //}
ngoldin 1:c1845f088b5d 72 // char c;
ngoldin 1:c1845f088b5d 73 // int pos = 0;
ngoldin 1:c1845f088b5d 74 // int res;
ngoldin 1:c1845f088b5d 75 // res=btbee_reset.read();
ngoldin 1:c1845f088b5d 76 // char res_c[30];
ngoldin 1:c1845f088b5d 77 // sprintf (res_c,"%d" ,res);
ngoldin 1:c1845f088b5d 78 // m3pi.print(res_c,1);
ngoldin 1:c1845f088b5d 79
ngoldin 1:c1845f088b5d 80 int * rawsens;
ngoldin 1:c1845f088b5d 81 int sens1;
ngoldin 1:c1845f088b5d 82 while(true){
ngoldin 1:c1845f088b5d 83 sens1=rawsens[0];
ngoldin 1:c1845f088b5d 84 t1.start();
ngoldin 1:c1845f088b5d 85 rawsens = m3pi.raw_sensor();
ngoldin 1:c1845f088b5d 86 t1.stop();
ngoldin 1:c1845f088b5d 87 wait(0.1);
ngoldin 1:c1845f088b5d 88 m3pi.cls();
ngoldin 1:c1845f088b5d 89 m3pi.locate(0,1);
ngoldin 1:c1845f088b5d 90 m3pi.printf("%d",rawsens[0]);
ngoldin 1:c1845f088b5d 91 m3pi.locate(0,0);
ngoldin 1:c1845f088b5d 92 m3pi.printf("%d",rawsens[0]-sens1);
ngoldin 1:c1845f088b5d 93 //m3pi.printf("%d",t1.read_ms());
ngoldin 1:c1845f088b5d 94 t1.reset();
ngoldin 0:546e224d2f88 95 }
ngoldin 1:c1845f088b5d 96 //wait(1.0);
ngoldin 1:c1845f088b5d 97
ngoldin 1:c1845f088b5d 98 /*
ngoldin 1:c1845f088b5d 99 while(m3pi_pb){
ngoldin 1:c1845f088b5d 100 m3pi_led[5]=!m3pi_led[5];
ngoldin 1:c1845f088b5d 101 wait(0.1);
ngoldin 1:c1845f088b5d 102 }
ngoldin 1:c1845f088b5d 103
ngoldin 1:c1845f088b5d 104 int ii=1;
ngoldin 1:c1845f088b5d 105 while (true) {
ngoldin 1:c1845f088b5d 106 m3pi_led[0]=1;
ngoldin 1:c1845f088b5d 107 m3pi_led[1]=0;
ngoldin 1:c1845f088b5d 108 if (btbee.writeable()) {
ngoldin 1:c1845f088b5d 109 if (ii==6){btbee.printf("end\n");}
ngoldin 1:c1845f088b5d 110 else {btbee.printf("Sensor %d. : %d \n",ii,rawsens[ii-1]);}
ngoldin 1:c1845f088b5d 111 m3pi_led[0]=0;
ngoldin 1:c1845f088b5d 112 ii++;
ngoldin 1:c1845f088b5d 113 m3pi.locate(0,0);
ngoldin 1:c1845f088b5d 114 m3pi.printf("Sent %0.3d",ii);
ngoldin 1:c1845f088b5d 115 }
ngoldin 1:c1845f088b5d 116
ngoldin 1:c1845f088b5d 117 while (btbee.readable()) {
ngoldin 1:c1845f088b5d 118 c = btbee.getc();
ngoldin 1:c1845f088b5d 119 m3pi.locate(pos,1);
ngoldin 1:c1845f088b5d 120 m3pi.print(&c,1);
ngoldin 1:c1845f088b5d 121 pos++;
ngoldin 1:c1845f088b5d 122 pos=pos%8;
ngoldin 1:c1845f088b5d 123
ngoldin 1:c1845f088b5d 124 }
ngoldin 1:c1845f088b5d 125
ngoldin 1:c1845f088b5d 126 wait(0.5);
ngoldin 1:c1845f088b5d 127 }
ngoldin 1:c1845f088b5d 128 */
ngoldin 0:546e224d2f88 129 }
ngoldin 1:c1845f088b5d 130
ngoldin 1:c1845f088b5d 131
ngoldin 1:c1845f088b5d 132