der Roboter / S1

Dependencies:   SensoryTest

Fork of btbee by Nikolas Goldin

Revision:
8:fd8a30a6923d
Child:
9:6ae4359b73df
diff -r 76a8ae1314a7 -r fd8a30a6923d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 20 13:36:31 2014 +0000
@@ -0,0 +1,37 @@
+#include "mbed.h"
+#include "m3pi_ng.h"
+
+m3pi thinggy;
+
+
+int main() {
+    
+    float speed = 0.1;
+    float threshold = 0.01;
+    
+    wait(2.0);
+    
+    thinggy.sensor_auto_calibrate();
+    while(1) {
+         // -1.0 is far left, 1.0 is far right, 0.0 in the middle
+        float position= thinggy.line_position();
+ 
+        // Line is more than the threshold to the right, slow the left motor
+        if (position > threshold) {
+            thinggy.right(speed);
+           
+        }
+ 
+        // Line is more than 50% to the left, slow the right motor
+        else if (position < -threshold) {
+            thinggy.left(speed);
+            
+        }
+ 
+        // Line is in the middle
+        else {
+            thinggy.forward(speed);
+        }
+    }
+}
+