This program pairs with an Android app to control the Magician robot via bluetooth. No correction is done to ensure that the motors are equal speeds.
Dependencies: Motordriver mbed
Revision 0:ed7c764766cb, committed 2014-10-19
- Comitter:
- Garr12100
- Date:
- Sun Oct 19 03:00:53 2014 +0000
- Commit message:
- MagicianBluetoothRemote;
Changed in this revision
diff -r 000000000000 -r ed7c764766cb Motordriver.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Motordriver.lib Sun Oct 19 03:00:53 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/littlexc/code/Motordriver/#3110b9209d3c
diff -r 000000000000 -r ed7c764766cb main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Oct 19 03:00:53 2014 +0000 @@ -0,0 +1,59 @@ +#include "mbed.h" +#include "motordriver.h" + +Serial pc(USBTX, USBRX); +Serial device(p9, p10); //Connect JY-MCU bluetooth module to 9,10 + +Motor right(p21, p22, p23, 1); // pwm, fwd, rev, has brake feature +Motor left(p26, p25, p24, 1); +float speed; + +int main() +{ + unsigned char Instr;//What button was sent? 1 = forward, 2 = backward + unsigned char sentSpeed; //What is the slider set to? + device.baud(57600); + while(1) { + + + if(device.readable()) { + Instr = device.getc(); + pc.printf("Instruction: %i\n\r", Instr); + wait(.05);//Wait for the next bluetooth value to be recieved. + if(device.readable()){ + sentSpeed = device.getc(); + switch (Instr){ + case 0://Stop + left.speed(0); + right.speed(0); + break; + case 1://Forward + pc.printf("Speed: %i\n\r", sentSpeed); + speed = float(sentSpeed) / 100; + left.speed(speed); + right.speed(speed); + break; + case 2://Reverse + pc.printf("Reverse speed: %i\n\r", sentSpeed); + speed = -float(sentSpeed) / 100; + left.speed(speed); + right.speed(speed); + break; + case 3://Clockwise Turn + speed = float(sentSpeed) / 100; + left.speed(speed); + right.speed(-speed); + break; + case 4://CCW Turn + speed = float(sentSpeed) / 100; + left.speed(-speed); + right.speed(speed); + break; + }//End Switch + + }//End Speed Read + }//End Instruction Read + + + } +} \ No newline at end of file
diff -r 000000000000 -r ed7c764766cb mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Oct 19 03:00:53 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file