Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SD.h"
- #define SD_ChipSelectPin 10
- #include "TMRpcm.h"
- #include "SPI.h"
- TMRpcm music;
- String voice;
- void setup() {
- music.speakerPin=9;
- Serial.begin(38400);
- if(!SD.begin(SD_ChipSelectPin))
- {
- Serial.println("SD fail");
- return;
- }
- music.setVolume(5);
- }
- //-----------------------------------------------------------------------//
- void loop() {
- while (Serial.available()){ //Check if there is an available byte to read
- delay(10); //Delay added to make thing stable
- char c = Serial.read(); //Conduct a serial read
- if (c == '#') {break;} //Exit the loop when the # is detected after the word
- voice += c; //Shorthand for voice = voice + c
- }
- if (voice.length() > 0) {
- Serial.println(voice);
- if(voice == "play faded")
- {
- music.play("faded.wav");
- }
- if(voice == "play hello")
- {
- music.play("hello.wav");
- }
- if(voice == "play alone")
- {
- music.play("alone.wav");
- }
Add Comment
Please, Sign In to add comment