BAT / Mbed 2 deprecated BAT_senior_design_Felipe

Dependencies:   SDFileSystem mbed-rtos mbed wave_player

Fork of BAT_senior_design by BAT

Files at this revision

API Documentation at this revision

Comitter:
aismail1997
Date:
Fri Oct 13 15:01:03 2017 +0000
Parent:
5:53a0eac0ffe1
Child:
7:7dcc36925c50
Commit message:
rtos failing

Changed in this revision

functions.cpp 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
servo.cpp Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/functions.cpp	Fri Oct 13 15:01:03 2017 +0000
@@ -0,0 +1,31 @@
+#include "wave_player.h"
+#include "SDFileSystem.h"
+
+void moveServoIn(PwmOut servo, DigitalIn pb)
+{
+    while(pb == 1)
+        //myled = 1;
+        // rotate 90 degrees one way
+        for(int i=3; i<=7; i++) {
+            servo = i/100.0;
+            wait(0.01);
+        }
+}
+
+void moveServoOut(PwmOut servo, DigitalIn pb)
+{
+    while(pb == 1)
+        //myled = 0;
+        for(int i=7; i>3; i--) {
+            servo = i/100.0;
+            wait(0.01);
+        }
+}
+
+void playSound(wave_player waver)
+{
+    FILE *wave_file;
+    wave_file=fopen("/sd/police_siren.wav","r");
+    waver.play(wave_file);
+    fclose(wave_file);
+}
\ No newline at end of file
--- a/main.cpp	Wed Oct 11 14:54:30 2017 +0000
+++ b/main.cpp	Fri Oct 13 15:01:03 2017 +0000
@@ -1,6 +1,6 @@
 #include "mbed.h"
-#include "wave_player.h"
-#include "SDFileSystem.h"
+#include "functions.cpp"
+#include "rtos.h"
 
 PwmOut myservo(p21);
 DigitalIn pb1 (p20);
@@ -11,61 +11,80 @@
 AnalogOut DACout(p26);
 wave_player waver(&DACout);
 
-void moveServoIn()
+// add start, mode, reset buttons
+
+
+
+
+// THREADS
+
+
+void button_thread()
 {
-    while(pb1 == 1)
-        //myled = 1;
-        // rotate 90 degrees one way
-        for(int i=3; i<=7; i++) {
-            myservo = i/100.0;
-            wait(0.01);
-        }
+
 }
 
-void moveServoOut()
+void submit_thread()
 {
-    while(pb1 == 1)
-        //myled = 0;
-        for(int i=7; i>3; i--) {
-            myservo = i/100.0;
-            wait(0.01);
-        }
+
 }
 
-void playSound()
+void start_thread()
 {
-    FILE *wave_file;
-    wave_file=fopen("/sd/police_siren.wav","r");
-    waver.play(wave_file);
-    fclose(wave_file);
+    // read pb_start
+    // if 1
+    start == 1;
+    // else 0
 }
 
 int main()
 {
-    pc.printf("begin\n");
-
+    // SETUP
     // button up: state = 0, button halfway: state = 1; button down: state = 2
     int state = 2;
-
     // pull up the pushbutton to prevent bouncing
     pb1.mode(PullUp);
     wait(.001);
-
     // servo begins at 30 degrees
     for(int i=0; i<=3; i++) {
         myservo = i/100.0;
         wait(0.01);
     }
 
-    while(1) {
+    // MAIN THREAD
+    while(true) {
+
+        // start threads for reset, mode, start
+        Thread t1(start_thread);
+
+        // setup SDcard and Speaker
+
+
+        // when started
+        while (start == 0) {}
+        Thread t2(button_thread);
+        Thread t3(submit_thread);
+
+        // when submitted
+        while (submit == 0) {}
+                
+
+        // start button threads and submit thread
+        // if submit close button threads and submit thread
+        // check result, speaker result
+        // save results
+
+
+
+
         // Servo code
         if (pb1 == 1 && state == 2) {
-            moveServoIn();
+            moveServoIn(myservo, pb1);
             state = 1;
         }
         // rotate 90 degrees other way
         if (pb1 == 1 && state == 1) {
-            moveServoOut();
+            moveServoOut(myservo, pb1);
             state = 2;
         }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Fri Oct 13 15:01:03 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#5713cbbdb706