Guest User

Arduino bluetooth wav player

a guest
Sep 8th, 2017
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include "SD.h"
  2. #define SD_ChipSelectPin 10
  3. #include "TMRpcm.h"
  4. #include "SPI.h"
  5. TMRpcm music;
  6. String voice;
  7.  
  8.  
  9. void setup() {
  10. music.speakerPin=9;
  11. Serial.begin(38400);
  12. if(!SD.begin(SD_ChipSelectPin))
  13. {
  14. Serial.println("SD fail");
  15. return;
  16. }
  17. music.setVolume(5);
  18. }
  19. //-----------------------------------------------------------------------//
  20. void loop() {
  21. while (Serial.available()){ //Check if there is an available byte to read
  22. delay(10); //Delay added to make thing stable
  23. char c = Serial.read(); //Conduct a serial read
  24. if (c == '#') {break;} //Exit the loop when the # is detected after the word
  25. voice += c; //Shorthand for voice = voice + c
  26. }
  27. if (voice.length() > 0) {
  28. Serial.println(voice);
  29.  
  30. if(voice == "play faded")
  31. {
  32. music.play("faded.wav");
  33. }
  34.  
  35. if(voice == "play hello")
  36. {
  37. music.play("hello.wav");
  38. }
  39.  
  40. if(voice == "play alone")
  41. {
  42. music.play("alone.wav");
  43. }
Add Comment
Please, Sign In to add comment