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
arduino
#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);
}
}
test_code.rar (2.86 MB)