A short test program for all things m3pi and BtBee.

Dependencies:   btbee m3pi_ng mbed

Fork of m3pi_btTest by Nikolas Goldin

Revision:
2:35d1143053d3
Parent:
1:c1845f088b5d
Child:
3:545c4c50dc0f
diff -r c1845f088b5d -r 35d1143053d3 main.cpp
--- a/main.cpp	Mon May 13 10:55:33 2013 +0000
+++ b/main.cpp	Tue May 14 11:05:52 2013 +0000
@@ -8,30 +8,30 @@
 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
+Serial btbee(p28, p27); // tx rx
+DigitalOut btbee_reset(p26);  // 0 resets the device
+
 //Serial btbee(p27, p28); // tx rx
+
 int main()
 {
+    // initialization stuff ////////////////////////////////////////////////////////////////////////////////////////////////////
     m3pi.locate(0,1);
-    //btbee_reset=1;  // else it keeps resetting
-    mbed_led[0] = 1;
-    mbed_led[1] = 1;
-    mbed_led[2] = 1;
-    mbed_led[3] = 1;
+    btbee_reset=1;  // else it keeps resetting
+    for (int i = 0; i <4; i++) {
+        mbed_led[i] = 0;
+    }
+    for (int i = 0; i <8; i++) {
+        m3pi_led[i]=0;
+    }
     m3pi_pb.mode(PullUp); // expected would be 1 when pb is pressed, 0 when not, opposite is the case
     //btbee.baud(38400);  // this is BtBee default for AT commands
     //btbee.baud(9600);  // this is BtBee default for regular commands
     //btbee.format();  // the default should be fine
-    
-    
-    /*
-    for (int i = 0; i <8; i++) {
-        m3pi_led[i]=1;
-    }
-    */
-    
-    /*  THIS IS NOT DOCUMENTED???
+    // 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);
     */
@@ -42,66 +42,64 @@
     //the number of characters in the array
     //int len=49;
     //m3pi.playtune(dixie,len);
-    
-    /*
-    wait(1); // 1 second
-    mbed_led[0] = 0;
-    mbed_led[1] = 0;
-    mbed_led[2] = 0;
-    mbed_led[3] = 0;
 
-    for (int i = 0; i <8; i++) {
-        m3pi_led[i]=0;
-    }
-    */
-    
     /*
     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);
-    m3pi.locate(0,1);
     */
-    
-
-    //while (true){
-    //m3pi_led[0]=!m3pi_pb;
-    //}
-//    char c;
-//    int pos = 0;
-//    int res;
-//    res=btbee_reset.read();
-//    char res_c[30];
-//    sprintf (res_c,"%d" ,res);
-//    m3pi.print(res_c,1);
 
-    int * rawsens;
-    int sens1;
-    while(true){
-    sens1=rawsens[0];
-    t1.start();
-    rawsens = m3pi.raw_sensor();
-    t1.stop();
-    wait(0.1);
-    m3pi.cls();  
-    m3pi.locate(0,1);     
-    m3pi.printf("%d",rawsens[0]);
-    m3pi.locate(0,0);
-    m3pi.printf("%d",rawsens[0]-sens1);         
-    //m3pi.printf("%d",t1.read_ms());
-    t1.reset();
+    /*
+    // tests for the pushbutton
+    while (true){
+    m3pi_led[0]=!m3pi_pb;
     }
-    //wait(1.0);
-    
-    /*
+
     while(m3pi_pb){
     m3pi_led[5]=!m3pi_led[5];
     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;
     while (true) {
         m3pi_led[0]=1;
         m3pi_led[1]=0;
@@ -120,7 +118,7 @@
             m3pi.print(&c,1);
             pos++;
             pos=pos%8;
-            
+
         }
 
         wait(0.5);