Go Down

Topic: Bluetooth sensor can't receive message (Read 115 times) previous topic - next topic

AKAI

I wnat to receive messages from phone and add variable to change songs.
Why the program can't receive message.Can't enter the while loop when I send message.
How can I change the program?
(mega2560,HC-06 Bluetooth and music shield V2)
music shield V2 must include Music_Shield-master library :smiley-roll-sweat:  :smiley-roll-sweat:  :smiley-roll-sweat:  :smiley-roll-sweat:

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

AKAI

do you know what's probmem in my program?
can you tell me.

zaxarias

z.p

AKAI

#include <SoftwareSerial.h>
#include <SD.h>
#include <SPI.h>
#include <arduino.h>
#include <MusicPlayer.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

char a;
int i=0;
void setup()
{

   Serial.begin(9600);     
        BTSerial.begin(9600);  // HC-06 current bound rate (default 9600)
       
                player.begin();                      //will initialize the hardware and set default mode to be normal.
   player.setPlayMode(PM_REPEAT_ONE); //set mode to repeat playing a song
   player.playOne("1.aac");          //play a song with its name

                player1.begin();                      //will initialize the hardware and set default mode to be normal.
   player1.setPlayMode(PM_REPEAT_ONE);
   player1.playOne("2.aac");

        player.digitalControlEnable();
               
        Serial.println("Let's DEMO");
       
}
void loop()
{
       
        if(i%2==0)
        {
          player.play();
          Serial.println("player play");
          delay(5000);
        }
        else
        {
          player1.play();
          Serial.println("player1 play");
          delay(5000);
        }
      //////////bluetooth
        while(BTSerial.available())
        {
            byte inByte = BTSerial.read();
            a=inByte;
       
        }
       
        if(a=='g')
        {
             Serial.print("receive g message");
             i++;
             //delay(1000);
        }
        if(a=='t')
        {
             Serial.print("receive t message");
             i++;
             //delay(1000);
        }
     
       
}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy