Code on Arduino: App via Bluetooth

Asked

Viewed 65 times

1

The image below shows the application I created to try to communicate with Arduin. 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 about how to codify this and also how the serial sending would work. Follow the image of the application.

inserir a descrição da imagem aqui

Below follows the code I tried to generate, but the same barely works(just runs the setup):

#include <SD.h>                      // need to include the SD library
#define SD_ChipSelectPin 53  //example uses hardware SS pin 53 on Mega2560
#include <TMRpcm.h>           //  also need to include this library...
TMRpcm tmrpcm;   // create an object for use in this sketch
char tema,escolha,controle;

void setup(){
  tmrpcm.speakerPin = 11; //11 on Mega, 9 on Uno, Nano, etc
  Serial.begin(9600);
  if (!SD.begin(SD_ChipSelectPin)) {  // see if the card is present and can be initialized:
    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;
      }
    }
  }
}

I’m sorry if I’m making some gross mistakes, but it’s my first attempt at applying with Adian. The same is taking the audios of an sd card. Below is the block code of the application. In short my biggest doubt is on how serial communication would work: if I check one of the options for example, it sent "a" always and therefore when pressing finalize choices I would be sending "a" and "d"? Doubts like that. inserir a descrição da imagem aqui

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.