Robotics Interest Club
/
m3pi_Bluetooth
m3pi_Bluetooth
Revision 0:f5a23eaeab89, committed 2017-04-27
- Comitter:
- eljerchua
- Date:
- Thu Apr 27 08:23:42 2017 +0000
- Commit message:
- m3pi_Bluetooth
Changed in this revision
diff -r 000000000000 -r f5a23eaeab89 m3pi.lib --- /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
diff -r 000000000000 -r f5a23eaeab89 main.cpp --- /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
diff -r 000000000000 -r f5a23eaeab89 mbed.bld --- /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