const int busyPin = 8;
byte volume = 0x40;
byte commandLength;
byte command[6];
int checkSum = 0;
int soundTrack = 114;
int PinButton1 = 10;
int val1 = 0;
int playStatus = 1;
int trackNumber = 4;
int randNumb1 = 0;
int randNumb2 =0;
void sendCommand(){
int q;
for(q=0;q<commandLength;q++){
Serial1.write(command[q]);
Serial.print(command[q],HEX);
}
Serial.println("End");
}
void stopPlay(){
command[0] = 0xAA;//first byte says it's a command
command[1] = 0x04;
command[2] = 0x00;
command[3] = 0xAE;
commandLength = 4;
sendCommand();
}
void regPlay(){
command[0] = 0xAA;//first byte says it's a command
command[1] = 0x02;
command[2] = 0x00;
command[3] = 0xAC;
commandLength = 4;
sendCommand();
}
void newPlay(){
command[0] = 0xAA;//first byte says it's a command
command[1] = 0x07;
command[2] = 0x02;
command[3] = trackNumber >> 8;
command[4] = trackNumber;
command[5] = (0xAA + 0x07 + 0x02 + (trackNumber >> 8) + trackNumber);
commandLength = 6;
sendCommand();
//int command[] = {0xAA, 0x07, 0x02, (byte)(trackNumber >> 8), (byte)(trackNumber & 0xFF), (byte)(0xAA + 0x07 + 0x02 + (trackNumber >> 8) + (trackNumber & 0xFF))};
//commandLength = 6;
/*uint16_t Mike[] = {124, 164, 725, 496, 8243};
int x;
for(x=0;x<5;x++){
Serial.print(Mike[x]);
//Serial.println(newCommand[x]);
}
Serial.println("End");*/
//sendCommand();
//Serial1.write(command, sizeof(command));
//Serial.print(command);
}
void setup() {
Serial.begin(115200);
Serial1.begin(9600);
delay(1000);
Serial.println("DYSV5Wv4");
pinMode(PinButton1, INPUT);
}
void loop() {
val1=digitalRead(PinButton1);
randNumb1 = (rand() % 10);
Serial.println(randNumb1);
delay(randNumb1*100);
switch (playStatus) {
case 1:
if (val1 == HIGH) {
playStatus = 2;
//Serial.print("Mike");
newPlay();
//regPlay();
/*command[0] = 0xAA;//first byte says it's a command
command[1] = 0x07;
command[2] = 0x02;
command[3] = highByte(soundTrack);//snh...track HIGH bit
command[4] = lowByte(soundTrack);//SNL... track low bit
checkSum = 0;
for (int q = 0; q < 5; q++) {
checkSum += command[q];
}
command[5] = lowByte(checkSum);//SM check bit... low bit of the sum of all previous values
commandLength = 6;
sendCommand();*/
delay(100);
//regPlay();
//delay(1000);
//newPlay();
}
break;
case 2:
if(val1 == LOW){
playStatus = 1;
//newPlay();
stopPlay();
delay(100);
}
break;
default:
break;
}
}
/*
byte volume = 0x40;
byte commandLength;
byte command[6];
int checkSum = 0;
int soundTrack = 3;
void sendCommand(){
int q;
for(q=0;q<commandLength;q++){
Serial1.write(command[q]);
Serial.print(command[q],HEX);
}
Serial.println("End");
}
void setup() {
Serial.begin(115200);
Serial1.begin(9600);
Serial.println("DYSV5Wv4");
//set volume to 17
command[0] = 0xAA;//first byte says it's a command
command[1] = 0x13;
command[2] = 0x01;
command[3] = 17;//volume
checkSum = 0;
for(int q=0;q<4;q++){
checkSum += command[q];
}
command[4] = lowByte(checkSum);//SM check bit... low bit of the sum of all previous values
commandLength = 5;
sendCommand();
/*
//select random mode
command[0] = 0xAA;//first byte says it's a command
command[1] = 0x18;
command[2] = 0x01;
command[3] = 0x03;//random
checkSum = 0;
for(int q=0;q<4;q++){
checkSum += command[q];
}
command[4] = lowByte(checkSum);//SM check bit... low bit of the sum of all previous values
commandLength = 5;
sendCommand();
//pick track
command[0] = 0xAA;//first byte says it's a command
command[1] = 0x07;
command[2] = 0x02;
command[3] = highByte(soundTrack);//snh...track HIGH bit
command[4] = lowByte(soundTrack);//SNL... track low bit
checkSum = 0;
for (int q = 0; q < 5; q++) {
checkSum += command[q];
}
command[5] = lowByte(checkSum);//SM check bit... low bit of the sum of all previous values
commandLength = 6;
sendCommand();
/*
//play track
command[0] = 0xAA;//first byte says it's a command
command[1] = 0x02;
command[2] = 0x00;
command[3] = 0xAC;
commandLength = 4;
sendCommand();
}
void loop() {
}
/*byte commandLength;
byte command[5];
int checkSum = 0;
int trackNum = 4;
void playTrack(int soundTrack) {
command[0] = 0xAA;//first byte says it's a command
command[1] = 0x07;
command[2] = 0x02;
command[3] = highByte(soundTrack);//snh...track HIGH bit
command[4] = lowByte(soundTrack);//SNL... track low bit
checkSum = 0;
for (int q = 0; q < 5; q++) {
checkSum += command[q];
}
command[5] = lowByte(checkSum);//SM check bit... low bit of the sum of all previous values
commandLength = 6;
sendCommand();
}
void playbackVolume(int vol) {
if (vol > 30) { //check within limits
vol = 30;
}
command[0] = 0xAA;//first byte says it's a command
command[1] = 0x13;
command[2] = 0x01;
command[3] = vol;//volume
checkSum = 0;
for (int q = 0; q < 4; q++) {
checkSum += command[q];
}
command[4] = lowByte(checkSum);//SM check bit... low bit of the sum of all previous values
commandLength = 5;
//Serial.println("Mid");
sendCommand();
}
void sendCommand() {
//Serial.println("send");
int q;
for (q = 0; q < commandLength; q++) {
Serial1.write(command[q]);
Serial.print(command[q], HEX);
}
Serial.println("End");
}
void setup() {
Serial.begin(115200);
Serial1.begin(9600);
playbackVolume(18);//sets volume to lvl 17
}
void loop() {
playTrack(trackNum);
delay(3000);
}
//const int busyPin = 8;//change to any suitable digital pin
byte commandLength;
byte command[5];
int checkSum = 0;
int trackNum = 4;
//int playStatus; //0 playing 1 stopped 2 waiting to start next track
//unsigned long lastCheckTime;
//unsigned long currentMillis;
//int busyPinstate = 0;
void playTrack(int soundTrack) {
//Serial.println("playtrack");
//select track
//Serial.print("soundTrack: ");
//Serial.println(soundTrack);
command[0] = 0xAA;//first byte says it's a command
command[1] = 0x07;
command[2] = 0x02;
command[3] = highByte(soundTrack);//snh...track HIGH bit
command[4] = lowByte(soundTrack);//SNL... track low bit
checkSum = 0;
for (int q = 0; q < 5; q++) {
checkSum += command[q];
}
command[5] = lowByte(checkSum);//SM check bit... low bit of the sum of all previous values
commandLength = 6;
//Serial.println("playtrack");
sendCommand();
}
//plays whatever track has been paused or 1st track if nothing selected
//May need to be selected after putting into random mode
/*void play() {
Serial.println("play");
command[0] = 0xAA;//first byte says it's a command
command[1] = 0x02;
command[2] = 0x00;
command[3] = 0xAC;
commandLength = 4;
sendCommand();
}*/
/*
//sets the device volume...0 - 30
void playbackVolume(int vol) {
//Serial.println("playbackvolume");
if (vol > 30) { //check within limits
vol = 30;
}
command[0] = 0xAA;//first byte says it's a command
command[1] = 0x13;
command[2] = 0x01;
command[3] = vol;//volume
checkSum = 0;
for (int q = 0; q < 4; q++) {
checkSum += command[q];
}
command[4] = lowByte(checkSum);//SM check bit... low bit of the sum of all previous values
commandLength = 5;
//Serial.println("Mid");
sendCommand();
}
//sends the command
void sendCommand() {
//Serial.println("send");
int q;
for (q = 0; q < commandLength; q++) {
Serial1.write(command[q]);
Serial.print(command[q], HEX);
}
Serial.println("End");
}
void setup() {
//Serial.println("setup");
Serial.begin(115200);
Serial1.begin(9600);
//Serial.println("DYSV5Wv7");
//pinMode(busyPin, INPUT);//pin to read from DY-SV5W buyPin
playbackVolume(18);//sets volume to lvl 17
}
void loop() {
playTrack(trackNum);
delay(1000);
//break;
}
/*
void loop() {
//Serial.println("loop");
currentMillis = millis();//stores time in millis() for non blocking timings
busyPinstate = digitalRead(busyPin);
if (busyPinstate > 0) { //nothing playing
if (playStatus < 1) {
playStatus = 1;
lastCheckTime = currentMillis;//set system ready for 2 sec delay
}
}
switch (playStatus) {
case 1:
if (currentMillis - lastCheckTime >= 2000) { //2000 = 2 seconds of silence between tracks
playStatus = 2;
trackNum = 4;//fixed track number
playTrack(trackNum);
}
break;
case 2:
if(busyPinstate < 1){
playStatus = 0;
}
break;
default:
break;
}
}*/