Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 3:6ec54d838b44
- Parent:
- 2:d8db9db36fb7
- Child:
- 4:d58b9ad5d43d
--- a/main.cpp Fri Oct 17 15:24:58 2014 +0000 +++ b/main.cpp Sun Feb 15 08:04:49 2015 +0000 @@ -5,20 +5,20 @@ #define LM2_ D7 #define RM1_ D6 #define RM2_ D5 -#define RX_ D0 -#define TX_ D1 +#define RX_ PTC14 +#define TX_ PTC15 PwmOut LM1(LM1_); // motors configuration PwmOut LM2(LM2_); PwmOut RM1(RM1_); PwmOut RM2(LM2_); -//Serial link(TX_, RX_); // bluetooth serial port -Serial link(USBTX, USBRX); // usb serial port +Serial link(TX_, RX_); // bluetooth serial port +//Serial link(USBTX, USBRX); // usb serial port void analogWrite(mbed::PwmOut *prt, char spd) // write to PWM { - float a = spd / 2.56; // convert 0..256 to '%' + float a = spd / 256.0; // convert 0..256 to 0..1 *prt = a; } @@ -85,7 +85,7 @@ str[2] = d + 48; } -char toupper(char ch) +char tolower(char ch) { if (ch >= 'a' && ch <= 'z') return ch; if (ch >= 'A' && ch <= 'Z') return ch - 'A' + 'a'; @@ -95,7 +95,7 @@ int main(void) { char dat[5], b, i; - link.baud(9600); + link.baud(115200); initEcho(); // initialize echo sensor GoForward(0); // stop all motors @@ -104,26 +104,30 @@ while (true) { - if(link.readable()) // read data from blutooth serial port + link.printf("Take a sequence\n\r"); + + for (i=0; i<5; i++) { - for (i=0; i<5; i++) + while (!link.readable()); dat[i] = link.getc(); - } - - b = toupper(dat[0]); - + } + + b = tolower(dat[0]); int spd = charToInt(dat[1],dat[2],dat[3]); + + if (b == 'f') GoForward(spd); // movements + if (b == 'b') GoBack(spd); + if (b == 'r') TurnRight(spd); + if (b == 'l') TurnLeft(spd); + if (b == 'n') GoForward(0); - if (b == 'F') GoForward(spd); // movements - if (b == 'B') GoBack(spd); - if (b == 'R') TurnRight(spd); - if (b == 'L') TurnLeft(spd); - if (b == 'N') GoForward(0); - - if (b == 'E') // echo sensor + if (b == 'e') // echo sensor { intToChar(getEcho()); link.printf(str); } + + //link.printf(dat); + link.printf("%c%d ",b,spd); } } \ No newline at end of file