An m3pi demo program for Bluetooth control.

Dependencies:   X_NUCLEO_53L0A1 m3pi mbed

Fork of m3pi_BT by Alexander Saad-Falcon

Files at this revision

API Documentation at this revision

Comitter:
xmanwms95
Date:
Wed May 03 03:43:44 2017 +0000
Parent:
3:d5da5e6bc16f
Commit message:
An m3pi demo program for Bluetooth control.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r d5da5e6bc16f -r e2ab59ab0c80 main.cpp
--- a/main.cpp	Mon May 01 02:11:02 2017 +0000
+++ b/main.cpp	Wed May 03 03:43:44 2017 +0000
@@ -11,34 +11,36 @@
     m3pi.locate(0,1);
     m3pi.printf("YO");
 
-    bt.baud(9600); //make sure the baud rate is 9600
     while (!bt.readable()) { } //wait until the bt is ready
 
+///////LED change will register if the command was recieved or not
     while(1) {
-        led = !led;
-        if (bt.getc() == '!') {
-            if (bt.getc() == 'O') {
-                if (bt.getc()=='F') {
-                    m3pi.forward(.25);
-                }
-                if (bt.getc()=='B') {
-                    m3pi.backward(.25);
-                }
-                if (bt.getc()=='L') {
-                    m3pi.left(.25);
-                }
-                if (bt.getc()=='R') {
-                    m3pi.right(.25);
-                }
-                if (bt.getc()=='S') {
-                    m3pi.stop();
-                }
-                if (bt.getc()=='X') {
-                    pong = 1;
-                    wait(.001);
-                    pong = 0;
-                }
-            }
+
+        if (bt.getc()=='F') {
+            m3pi.forward(.25);
+            led = !led;
+        }
+        if (bt.getc()=='B') {
+            m3pi.backward(.25);
+            led = !led;
+        }
+        if (bt.getc()=='L') {
+            m3pi.left(.25);
+            led = !led;
+        }
+        if (bt.getc()=='R') {
+            m3pi.right(.25);
+            led = !led;
+        }
+        if (bt.getc()=='S') {
+            m3pi.stop();
+            led = !led;
+        }
+        if (bt.getc()=='X') {
+            pong = 1;
+            led = !led;
+            wait(.001);
+            pong = 0;
         }
         while (bt.readable()) char temp = bt.getc(); //flush buffer
     }