m3pi_Bluetooth

Dependencies:   m3pi mbed

Files at this revision

API Documentation at this revision

Comitter:
eljerchua
Date:
Thu Apr 27 08:23:42 2017 +0000
Commit message:
m3pi_Bluetooth

Changed in this revision

m3pi.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m3pi.lib	Thu Apr 27 08:23:42 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/chris/code/m3pi/#4b7d6ea9b35b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Apr 27 08:23:42 2017 +0000
@@ -0,0 +1,62 @@
+#include "mbed.h"
+#include "m3pi.h"
+
+m3pi m3pi;
+Serial device(p28, p27);
+DigitalIn pushbutton(p21);
+DigitalIn IR_centre(p8);
+DigitalIn IR_right(p11);
+DigitalIn IR_left(p30);
+DigitalOut led1(p20);
+
+void forward(float speed)
+{
+    m3pi.right_motor(speed);
+    m3pi.left_motor(speed);
+}
+
+void backward(float speed)
+{
+    m3pi.right_motor(-speed);
+    m3pi.left_motor(-speed);
+}
+
+void turnright(float speed)
+{
+    m3pi.right_motor(speed);
+    m3pi.left_motor(-speed);
+}
+
+void turnleft(float speed)
+{
+    m3pi.right_motor(-speed);
+    m3pi.left_motor(speed);
+}
+
+void stop()
+{
+    m3pi.right_motor(0);
+    m3pi.left_motor(0);
+}
+
+int main()
+{
+    device.baud(115200);
+    float speed = 0.5;
+    char c = 'k', a;
+    while(true) 
+    {
+        if(device.readable())
+        {
+            a = device.getc();
+            if(a > 0 && a <= 100) speed = a*1.0/100;
+            else c = a;
+        }
+        
+        if(c == 'g') forward(speed);
+        else if(c == 'h') backward(speed);
+        else if(c == 'e') turnright(speed);
+        else if(c == 'f') turnleft(speed);
+        else stop();
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Apr 27 08:23:42 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/97feb9bacc10
\ No newline at end of file