Cat food dispenser demo.
Dependencies: SDFileSystem Servo mbed wave_player
Fork of WavePlayer_HelloWorld by
main.cpp@2:bd7893fa4301, 2016-10-28 (annotated)
- Committer:
- jeremycai3721
- Date:
- Fri Oct 28 15:20:08 2016 +0000
- Revision:
- 2:bd7893fa4301
- Parent:
- 1:5b8e223e983d
Done
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jeremycai3721 | 2:bd7893fa4301 | 1 | // Simple Cat Food Dispenser |
jeremycai3721 | 2:bd7893fa4301 | 2 | // Jeremy Xiaoyi Cai |
4180_1 | 1:5b8e223e983d | 3 | |
4180_1 | 1:5b8e223e983d | 4 | #include "mbed.h" |
jeremycai3721 | 2:bd7893fa4301 | 5 | #include "Servo.h" |
4180_1 | 1:5b8e223e983d | 6 | #include "SDFileSystem.h" |
4180_1 | 1:5b8e223e983d | 7 | #include "wave_player.h" |
4180_1 | 1:5b8e223e983d | 8 | |
jeremycai3721 | 2:bd7893fa4301 | 9 | // SD card |
jeremycai3721 | 2:bd7893fa4301 | 10 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
jeremycai3721 | 2:bd7893fa4301 | 11 | // Waveplayer |
4180_1 | 1:5b8e223e983d | 12 | AnalogOut DACout(p18); |
4180_1 | 1:5b8e223e983d | 13 | wave_player waver(&DACout); |
jeremycai3721 | 2:bd7893fa4301 | 14 | // Bluetooth |
jeremycai3721 | 2:bd7893fa4301 | 15 | Serial blue(p28,p27); |
jeremycai3721 | 2:bd7893fa4301 | 16 | // Servo |
jeremycai3721 | 2:bd7893fa4301 | 17 | Servo myservo(p21); |
4180_1 | 1:5b8e223e983d | 18 | |
4180_1 | 1:5b8e223e983d | 19 | int main() |
4180_1 | 1:5b8e223e983d | 20 | { |
jeremycai3721 | 2:bd7893fa4301 | 21 | // Adjust servo to default position |
jeremycai3721 | 2:bd7893fa4301 | 22 | myservo = 0.0; |
jeremycai3721 | 2:bd7893fa4301 | 23 | |
jeremycai3721 | 2:bd7893fa4301 | 24 | while(1) { |
jeremycai3721 | 2:bd7893fa4301 | 25 | // Check whether user is sending "feed" through bluetooth |
jeremycai3721 | 2:bd7893fa4301 | 26 | if (blue.getc()=='f') { |
jeremycai3721 | 2:bd7893fa4301 | 27 | if (blue.getc()=='e') { |
jeremycai3721 | 2:bd7893fa4301 | 28 | if (blue.getc()=='e') { |
jeremycai3721 | 2:bd7893fa4301 | 29 | if (blue.getc()=='d') { |
jeremycai3721 | 2:bd7893fa4301 | 30 | // After receiving "feed", start dispensing cat food |
jeremycai3721 | 2:bd7893fa4301 | 31 | myservo = 0.7; |
jeremycai3721 | 2:bd7893fa4301 | 32 | wait(1); |
jeremycai3721 | 2:bd7893fa4301 | 33 | myservo = 0.0; |
jeremycai3721 | 2:bd7893fa4301 | 34 | wait(0.5); |
jeremycai3721 | 2:bd7893fa4301 | 35 | |
jeremycai3721 | 2:bd7893fa4301 | 36 | // Play wav file on SD |
jeremycai3721 | 2:bd7893fa4301 | 37 | FILE *wave_file; |
jeremycai3721 | 2:bd7893fa4301 | 38 | wave_file=fopen("/sd/food.wav","r"); |
jeremycai3721 | 2:bd7893fa4301 | 39 | waver.play(wave_file); |
jeremycai3721 | 2:bd7893fa4301 | 40 | fclose(wave_file); |
jeremycai3721 | 2:bd7893fa4301 | 41 | |
jeremycai3721 | 2:bd7893fa4301 | 42 | } |
jeremycai3721 | 2:bd7893fa4301 | 43 | } |
jeremycai3721 | 2:bd7893fa4301 | 44 | } |
jeremycai3721 | 2:bd7893fa4301 | 45 | } |
jeremycai3721 | 2:bd7893fa4301 | 46 | } |
4180_1 | 1:5b8e223e983d | 47 | } |