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.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:c5b58b10970d
- Parent:
- 0:da3669e7df20
- Child:
- 2:f0610c06721d
--- a/main.cpp Mon Jan 14 22:37:46 2019 +0000
+++ b/main.cpp Wed Jan 16 17:38:09 2019 +0000
@@ -14,10 +14,9 @@
#define LEFT 3
#define RIGHT 4
-//For coloiur detection
+//For colour detection
#define COLOUR_THRESHOLD 150 //Will have to tune this value
-//For line following
DigitalOut myled(LED1); // Debug led
@@ -72,14 +71,16 @@
void setSpeed(int pulsewidth_us);
void setLeftMotorSpeed(int pulsewidth_us);
void setRightMotorSpeed(int pulsewidth_us);
- void setLeftMotorMode(int mode);
- void setRightMotorMode(int mode);
void stopMotors();
void goForward();
void goBackward();
void turnLeft();
void turnRight();
void changeDirection(int direction);
+
+ private:
+ void setLeftMotorMode(int mode);
+ void setRightMotorMode(int mode);
};
void MotorController::initialize()
@@ -341,31 +342,38 @@
int LineFollower::chooseDirection() {
- int sensorData = 0000 & ((lineDetected1 << 02) + (lineDetected2 << 01) + (lineDetected3));
+ int sensorData = 0x00 & ((lineDetected1 << 2) + (lineDetected2 << 1) + (lineDetected3));
+ sensorData = sensorData & 0x07
switch(sensorData) {
- case 0000:
+ //000
+ case 0x0
direction = STOP;
break;
- case 0001:
+ //001
+ case 0x1:
direction = RIGHT;
break;
- case 0010:
+ //010
+ case 0x2:
direction = FORWARD;
break;
- case 0011:
+ //011
+ case 0x3:
direction = RIGHT;
break;
- case 0100:
+ //100
+ case 0x4:
direction = LEFT;
break;
- case 0101:
+ //101
+ case 0x5:
if(red_path) {
direction = LEFT;
}
@@ -375,8 +383,14 @@
}
break;
-
- case 0111:
+
+ //110
+ case 0x06:
+ direction = RIGHT;
+ break;
+
+ //111
+ case 0x7:
direction = FORWARD;
break;
@@ -440,13 +454,13 @@
paper_detected = false;
}
- //Drop the disc once the second paper is detected
+ //Drop the disc once the second blue paper is detected
if(colourSensor.blue_detected && blue_path && !paper_detected && solenoidController.state) {
paper_detected = true;
solenoidController.off();
}
- //Drop the disc once the second paper is detected
+ //Drop the disc once the second red paper is detected
if(colourSensor.red_detected && red_path && !paper_detected && solenoidController.state) {
paper_detected = true;
solenoidController.off();