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:
- 11:055ee1a3cb75
- Parent:
- 10:57a0c57cabac
- Child:
- 12:8ae6609a66bf
--- a/main.cpp Sun Oct 16 18:03:21 2016 +0000 +++ b/main.cpp Fri Oct 21 10:30:20 2016 +0000 @@ -2,6 +2,8 @@ #include "Servo.h" #define DISTANCE 0.45 +#define VBORDER 0.5 //VBORDER being the LDR voltage value when going from the black line to the white surface and vice versa + Serial pc (USBTX, USBRX); // USB serial interface @@ -28,8 +30,8 @@ float front; float left; // float right; -// float LDRvalueleft; -// float LDRvalueright; + float LDRvalueleft; + float LDRvalueright; // set the USB serial interface baud rate pc.baud(921600); @@ -41,11 +43,11 @@ front = IRfront.read(); left = IRleft.read(); // right = IRright.read(); -// LDRvalueright = LDRright.read(); -// LDRvalueleft = LDRleft.read(); //output voltage of the LDR used for line following feature + LDRvalueright = LDRright.read(); + LDRvalueleft = LDRleft.read(); //output voltage of the LDR used for line following feature /***************************************************************************** - / if (front > DISTANCE) { Collision avoidance system only,the robot will move away from an obstacle/wall if getting to close to it + / if (front > DISTANCE) { Collision avoidance system only,the robot will move away from an obstacle/wall if getting to close to it, backup program if the following doesn't work / if (left > DISTANCE) { / ServoRight.write(0.5); //turn right / ServoLeft.write(0.4); @@ -110,6 +112,22 @@ } else if (front < DISTANCE) { //follow line + if (LDRvalueright < VBORDER && LDRvalueleft > VBORDER){ + // turn right + + } + if (LDRvalueright > VBORDER && LDRvalueleft < VBORDER){ + //turn left + + } + if LDRvalueright = VBORDER && LDRvalueright = VBORDER) { + //go straight + + } + + + + } } } \ No newline at end of file