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:
- 6:1056ed1d6d97
- Parent:
- 5:92510334cdfe
- Child:
- 7:1e5fa5952695
diff -r 92510334cdfe -r 1056ed1d6d97 main.cpp
--- a/main.cpp Fri Mar 01 15:34:17 2019 +0000
+++ b/main.cpp Mon Mar 04 10:52:03 2019 +0000
@@ -5,13 +5,13 @@
#define ON 1
//For motor control
-#define PWM_PERIOD_US 100 //For setting PWM periods to 1 milliseconds. I made this number up
+#define PWM_PERIOD_US 30000 //For setting PWM periods to 1 milliseconds. I made this number up
#define STOP 0
#define FORWARD 1
#define BACKWARD 2
//For line following, use the previous defines and the follwoing
-#define LEFT 4
-#define RIGHT 3
+#define LEFT 3
+#define RIGHT 4
DigitalOut redled(LED_RED); //Debiug LED
DigitalOut blueled(LED_BLUE);
@@ -19,7 +19,6 @@
I2C i2c(PTC9, PTC8); //pins for I2C communication (SDA, SCL)
-
//Set PWMs for controlling the H-bridge for the motor speed
PwmOut PWMmotorLeft(PTA4); //Connect to EN1 of L298N
PwmOut PWMmotorRight(PTA5); //Connect to EN1 of L298N
@@ -30,9 +29,9 @@
DigitalOut solenoid(PTC3); //Switch for the solenoid
//For black line detection
-AnalogIn QTR3A_3(PTB0);
+AnalogIn QTR3A_1(PTB0);
AnalogIn QTR3A_2(PTB1);
-AnalogIn QTR3A_1(PTB2);
+AnalogIn QTR3A_3(PTB2);
Serial bluetooth(PTE0,PTE1);
@@ -180,22 +179,22 @@
case FORWARD:
goForward();
- setSpeed(10);
+ setSpeed(PWM_PERIOD_US * 0.3);
break;
case BACKWARD:
goBackward();
- setSpeed(10);
+ setSpeed(PWM_PERIOD_US * 0.3);
break;
case LEFT:
turnLeft();
- setSpeed(10);
+ setSpeed(PWM_PERIOD_US * 0.3);
break;
case RIGHT:
turnRight();
- setSpeed(10);
+ setSpeed(PWM_PERIOD_US * 0.3);
break;
}
}
@@ -486,6 +485,8 @@
return direction;
}
+
+
void bluetoothControl(MotorController motorController) {
bluetooth.baud(9600);
@@ -601,10 +602,11 @@
//Start off going straight
- motorController.setSpeed(700);
+ motorController.setSpeed(PWM_PERIOD_US * 0.2);
motorController.goForward();
+
while(true) {
redled = !redled;
@@ -612,6 +614,8 @@
bluetoothControl(motorController);
}
+
+
lineFollower.readSensors();
motorController.changeDirection(lineFollower.chooseDirection());
@@ -651,9 +655,6 @@
}
blueled = !blueled;
-
- wait(0.5);
-
}
}