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:
- 1:29eeaabaa8e1
- Parent:
- 0:341347d8ccbc
- Child:
- 2:d8db9db36fb7
--- a/main.cpp Wed Oct 15 15:09:43 2014 +0000 +++ b/main.cpp Fri Oct 17 15:20:32 2014 +0000 @@ -1,22 +1,19 @@ #include "mbed.h" +#include "echo_sensor.h" -#define trigPin_ PTC11 -#define echoPin_ PTC12 -#define volt_Pin_ PTB11 #define LM1_ D3 -#define LM2_ D5 +#define LM2_ D7 #define RM1_ D6 -#define RM2_ D7 +#define RM2_ D5 #define RX_ D0 #define TX_ D1 -#define SPEED_ 64 PwmOut LM1(LM1_); // motors configuration PwmOut LM2(LM2_); PwmOut RM1(RM1_); PwmOut RM2(LM2_); -//Serial link(TX_, RX_); // bluetooth 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 @@ -58,23 +55,6 @@ analogWrite(&RM2,0); } -/*int getEcho(void) // for a future... -{ - long duration, distance; - digitalWrite(trigPin,LOW); - delayMicroseconds(2000); - digitalWrite(trigPin, HIGH); - delayMicroseconds(1000); - digitalWrite(trigPin, LOW); - - duration = pulseIn(echoPin, HIGH); - distance = (duration/2) / 29.1; - - if (distance > 200) return 200; - if (distance < 0) return 0; - return distance; -}*/ - int charToInt(char a, char b, char c) { int ans; @@ -116,8 +96,7 @@ { char dat[5], b, i; link.baud(9600); - //pinMode(trigPin, OUTPUT); // for a future... - //pinMode(echoPin, INPUT); + initEcho(); // initialize echo sensor GoForward(0); // stop all motors while (link.readable()); // trying to fount the starting byte @@ -135,21 +114,16 @@ int spd = charToInt(dat[1],dat[2],dat[3]); - if (b == 'F') GoForward(spd); + 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 == 'V') // voltmeter - { - //intToChar(analogRead(volt_Pin) / 4); // for a future... - //Bridge.put("DAT",str); - } if (b == 'E') // echo sensor { - //intToChar(getEcho()); // for a future... - //Bridge.put("DAT",str); + intToChar(getEcho()); + link.printf(str); } } } \ No newline at end of file