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.
Fork of 3pi_Line_Follow by
Diff: code.cpp
- Revision:
- 0:008c53db1931
- Child:
- 1:d8c15d5b8eac
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/code.cpp Tue Mar 20 16:28:07 2018 +0000
@@ -0,0 +1,32 @@
+#include "main.h"
+
+void repeat()
+{
+ float speed = 0.5;
+
+
+ robot.scan();
+
+ // in range -1 to 1, no error when line is at 0.0
+ // number is negative when the line is to the left
+ // number is positive when the line is to the right
+ float position = robot.read_line();
+
+ robot.display_data();
+
+
+
+ float step = 0.4*position;
+ // + when line to right
+ // - for line to left
+
+
+ if (position < 0.0) { // line to the left...need to turn left
+ robot.left_motor(speed+step);
+ robot.right_motor(speed);
+ } else { // line to the right...need to turn right
+ robot.left_motor(speed);
+ robot.right_motor(speed-step);
+ }
+
+}
\ No newline at end of file
