Robot using IMU and IR sensor data to drive autonomously and create a map

Dependencies:   mbed mbed-rtos LSM9DS1_Library_cal Motor

Revision:
2:fcf6f5901ee6
Parent:
1:27c32ba9fe93
Child:
3:70f624c5fe26
--- a/main.cpp	Sun Apr 10 20:57:18 2016 +0000
+++ b/main.cpp	Sun Apr 10 21:23:17 2016 +0000
@@ -1,13 +1,40 @@
 #include "mbed.h"
+#include "rtos.h"
+
+AnalogIn infraredR(p20); //Right infrared distance sensor
+AnalogIn infraredL(p19); //Left infrared distance sensor
+AnalogIn infraredF(p17); //Front infrared distance sensor
+
+float leftDist, rightDist, frontDist; //Distances from robot to obstacles
 
-DigitalOut myled(LED1);
+void left_thread(void const *args) {
+    while (1) {
+        leftDist = infraredL * 3.3f;
+        Thread::wait(500);     //wait 1/2 second before updating
+        }
+}
+
+void right_thread(void const *args) {
+    while (1) {
+        rightDist = infraredR * 3.3f;
+        Thread::wait(500);     //wait 1/2 second before updating
+        }
+}
+
+void front_thread(void const *args) {
+    while (1) {
+        frontDist = infraredF * 3.3f;
+        Thread::wait(500);     //wait 1/2 second before updating
+        }
+}    
 
 int main() {
     //Test
+    Thread left(left_thread);
+    Thread right(right_thread);
+    Thread front(front_thread);
+    
     while(1) {
-        myled = 1;
-        wait(0.2);
-        myled = 0;
-        wait(0.2);
+        
     }
 }