Josh Williams / Mbed 2 deprecated final_project

Dependencies:   HC_SR04_Ultrasonic_Library Motor mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
juubs
Date:
Mon May 01 03:20:11 2017 +0000
Commit message:
ECE 4180 final project mbed code

Changed in this revision

HC_SR04_Ultrasonic_Library.lib Show annotated file Show diff for this revision Revisions of this file
Motor.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HC_SR04_Ultrasonic_Library.lib	Mon May 01 03:20:11 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/ejteb/code/HC_SR04_Ultrasonic_Library/#e0f9c9fb4cf3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.lib	Mon May 01 03:20:11 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/simon/code/Motor/#f265e441bcd9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 01 03:20:11 2017 +0000
@@ -0,0 +1,75 @@
+// Sweep the motor speed from full-speed reverse (-1.0) to full speed forwards (1.0)
+#include "mbed.h"
+#include "ultrasonic.h"
+#include "Motor.h"
+#include "rtos.h"
+
+Serial pc(USBTX, USBRX);
+Motor leftWheel(p21, p20, p19);
+Motor rightWheel(p22, p15, p14); // pwm, fwd, rev
+float speed = 0.5;  
+char input;
+
+void dist(int distance) {
+    //pc.printf("Distance %d mm\r\n", distance);
+    if (distance < 200) {
+        leftWheel.speed(0);
+        rightWheel.speed(0);
+    }
+}
+
+ultrasonic sonar(p6, p7, .1, 1, &dist);
+
+void motor_thread(void const *args) {
+    while(1) {
+        if (pc.readable()) {
+            input = pc.getc();
+
+            switch (input) {
+                case 'f':
+                    leftWheel.speed(speed);
+                    rightWheel.speed(speed);
+                    break;            
+            
+                case 'b':
+                    leftWheel.speed(-1 * speed);
+                    rightWheel.speed(-1 * speed);
+                    break;
+            
+                case 'l':
+                    leftWheel.speed(-.4);
+                    rightWheel.speed( .4);
+                    wait(1.1); //Turn left 90deg
+                    leftWheel.speed(0);
+                    rightWheel.speed(0);
+                    break;
+            
+                case 'r':  
+                    leftWheel.speed(.4);
+                    rightWheel.speed(-.4);
+                    wait(1.1); //Turn right 90deg
+                    leftWheel.speed(0);
+                    rightWheel.speed(0);  
+                    break;
+                
+                 case 's':   
+                    leftWheel.speed(0);
+                    rightWheel.speed(0);  
+                    break;
+                
+                default:
+                    break;
+            }
+        }
+    }
+}
+
+int main() {
+    pc.baud(115200);
+    pc.printf("hello\n");
+    Thread motor_t(motor_thread);
+    sonar.startUpdates();
+    while(1) {
+        sonar.checkDistance();
+    }   
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Mon May 01 03:20:11 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon May 01 03:20:11 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/97feb9bacc10
\ No newline at end of file