Test fork nhi

Dependencies:   SDFileSystem mbed-rtos mbed emic2

Fork of BAT_senior_design by BAT

Files at this revision

API Documentation at this revision

Comitter:
aismail1997
Date:
Wed Oct 11 14:51:39 2017 +0000
Parent:
3:9ed43e974156
Child:
5:53a0eac0ffe1
Commit message:
added speaker and SD card

Changed in this revision

SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
Servo.lib Show diff for this revision Revisions of this file
main.cpp 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
servo.cpp Show annotated file Show diff for this revision Revisions of this file
wave_player.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Wed Oct 11 14:51:39 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
--- a/Servo.lib	Fri Oct 06 13:43:36 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://os.mbed.com/users/simon/code/Servo/#36b69a7ced07
--- a/main.cpp	Fri Oct 06 13:43:36 2017 +0000
+++ b/main.cpp	Wed Oct 11 14:51:39 2017 +0000
@@ -1,51 +1,77 @@
 #include "mbed.h"
-#include "Servo.h"
-
-// Azra
+#include "wave_player.h"
+#include "SDFileSystem.h"
 
 PwmOut myservo(p21);
 DigitalIn pb1 (p20);
 //AnalogIn linpot(p20);
 Serial pc(USBTX, USBRX);
-DigitalOut myled(LED1);
+//DigitalOut myled(LED1);
+SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
+AnalogOut DACout(p26);
+wave_player waver(&DACout);
+
+void moveServoIn()
+{
+    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()
+{
+    while(pb1 == 1)
+        //myled = 0;
+        for(int i=7; i>3; i--) {
+            myservo = i/100.0;
+            wait(0.01);
+        }
+}
+
+void playSound()
+{
+    FILE *wave_file;
+    wave_file=fopen("/sd/police_siren.wav","r");
+    waver.play(wave_file);
+    fclose(wave_file);
+}
 
 int main()
 {
+    pc.printf("begin\n");
+
     // button up: state = 0, button halfway: state = 1; button down: state = 2
-    //int state = 0;
-    pc.printf("begin\n");
     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) {
         // Servo code
         if (pb1 == 1 && state == 2) {
-            while(pb1 == 1)
-                myled = 1;
-            // rotate 90 degrees one way
-            for(int i=3; i<=7; i++) {
-                myservo = i/100.0;
-                wait(0.01);
-            }
+            moveServoIn();
             state = 1;
         }
-        //wait(1.0);
         // rotate 90 degrees other way
         if (pb1 == 1 && state == 1) {
-            while(pb1 == 1)
-                myled = 0;
-            for(int i=7; i>3; i--) {
-                myservo = i/100.0;
-                wait(0.01);
-            }
-            //wait(0.1);
+            moveServoOut();
             state = 2;
         }
-        //wait(1.0);
+
+        // SD card code
+
+        // speaker code
 
         // read linear potentiometer
         //if (linpot < 0.5) {
--- a/mbed.bld	Fri Oct 06 13:43:36 2017 +0000
+++ b/mbed.bld	Wed Oct 11 14:51:39 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/675da3299148
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/63cdd78b2dc1
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wave_player.lib	Wed Oct 11 14:51:39 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/sravet/code/wave_player/#acc3e18e77ad