Arduino code: Bluetooth application

1

The image below shows the application I created to try to communicate with the arduino. Each option sends via serial a letter as shown on the screen. The point is that I need to ensure that the user follows an order: choose theme, finalize choice and control the generated audio. But I have serious doubts as to how to codify this and also how serial sending would work. Here is the image of the application.

BelowisthecodeItriedtogenerate,butitdoesnotwork(justrunsthesetup):

#include<SD.h>//needtoincludetheSDlibrary#defineSD_ChipSelectPin53//exampleuseshardwareSSpin53onMega2560#include<TMRpcm.h>//alsoneedtoincludethislibrary...TMRpcmtmrpcm;//createanobjectforuseinthissketchchartema,escolha,controle;voidsetup(){tmrpcm.speakerPin=11;//11onMega,9onUno,Nano,etcSerial.begin(9600);if(!SD.begin(SD_ChipSelectPin)){//seeifthecardispresentandcanbeinitialized:Serial.println("SD fail");  
    return;   // don't do anything more if not
  }
  tmrpcm.play("start.wav"); //the sound file "music" will play each time the arduino powers up, or is reset
}

void loop(){ 
  if(Serial.available()){
    while(1){
      tema = Serial.read();
      if(tema == 'a' || tema == 'b' || tema =='c'){
        break;   
      }
    }
    while(1){
      escolha = Serial.read();
      if(escolha == 'd'){
        break;
      }
    }
    if(tema == 'a'){
      tmrpcm.play("bolsa.wav");
    }
    else if(tema == 'b'){
      tmrpcm.play("tec.wav");
    }
    else if(tema == 'c'){
      tmrpcm.play("all.wav");
    }
    while(1){
      controle = Serial.read();
      if(controle =='e' || controle =='E'){
        tmrpcm.pause();
      }
      else if(controle =='f'){
        tmrpcm.stopPlayback();
      }
      if(tmrpcm.isPlaying() == 0){
        break;
      }
    }
  }
}

Sorry if I'm making some gross errors, but it's my first attempt at an application with the Arduino. The same is taking audios from a sd card. Below is the application block code. In summary my biggest doubt is how serial communication would work: if I check one of the options for example, it will always send "a" and therefore when I press the end choices I would be sending "a" and "d"? Doubts like that.

    
asked by anonymous 29.08.2017 / 14:01

0 answers