Cat food dispenser demo.

Dependencies:   SDFileSystem Servo mbed wave_player

Fork of WavePlayer_HelloWorld by jim hamblen

Files at this revision

API Documentation at this revision

Comitter:
jeremycai3721
Date:
Fri Oct 28 15:20:08 2016 +0000
Parent:
1:5b8e223e983d
Commit message:
Done

Changed in this revision

Servo.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Fri Oct 28 15:20:08 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Servo/#36b69a7ced07
--- a/main.cpp	Thu Jan 24 02:59:05 2013 +0000
+++ b/main.cpp	Fri Oct 28 15:20:08 2016 +0000
@@ -1,20 +1,47 @@
+// Simple Cat Food Dispenser
+// Jeremy Xiaoyi Cai
 
 #include "mbed.h"
+#include "Servo.h"
 #include "SDFileSystem.h"
 #include "wave_player.h"
 
-
-SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
-
+// SD card
+SDFileSystem sd(p5, p6, p7, p8, "sd");
+// Waveplayer
 AnalogOut DACout(p18);
-
 wave_player waver(&DACout);
+// Bluetooth
+Serial blue(p28,p27);
+// Servo
+Servo myservo(p21);
 
 int main()
 {
-    FILE *wave_file;
-    printf("\n\n\nHello, wave world!\n");
-    wave_file=fopen("/sd/sample.wav","r");
-    waver.play(wave_file);
-    fclose(wave_file);
+   // Adjust servo to default position
+   myservo = 0.0;
+
+    while(1) {
+        // Check whether user is sending "feed" through bluetooth
+        if (blue.getc()=='f') {
+            if (blue.getc()=='e') {
+                if (blue.getc()=='e') {
+                    if (blue.getc()=='d') {
+                        // After receiving "feed", start dispensing cat food
+                        myservo = 0.7;
+                        wait(1);
+                        myservo = 0.0;
+                        wait(0.5);
+                        
+                        // Play wav file on SD
+                        FILE *wave_file;
+                        wave_file=fopen("/sd/food.wav","r");
+                        waver.play(wave_file);
+                        fclose(wave_file);
+
+                    }
+                }
+            }
+        }
+    }
 }
\ No newline at end of file