I'm building a project that will play and turn off 3 tracks using the DFRobot0299 Mini player also 3 led to determine which track is playiing, I wish to monitor the busy pin on the player to detect when the track has stopped playing and switch of all leds, there is a selection switch that switches between teh remote control and the button control, besides using four individual buttons I wish to use a IR Remote, the library I'm using is IR libarary 3.7.
I was using the setup for the 2.x ir remote library and obtained all hex codes, when program compiled I then got an error on serial saying remote may not work correctly , so updated teh changes to 3.x ir remote link below.
it now prints completely different hex codes and in a reverse order not sure why.
not sure how to get teh busypin to work as all this is to do is turn off leds.
any help would be most greatful, code I have so far is below.
#include "Arduino.h";
#include "SoftwareSerial.h";
#include "DFRobotDFPlayerMini.h";
//#include "IRremote.h";
#include "IRremote.hpp";
SoftwareSerial mySoftwareSerial(10 , 11);
DFRobotDFPlayerMini myDFPlayer;
const int RECV_PIN = 12;
//IRrecv irrecv(RECV_PIN);
//decode_results results;
//unsigned long key_value;
const int selectionSW = 2;
const int buttonoff = 3;
const int buttontrack1 = 4;
const int buttontrack2 = 5;
const int buttontrack3 = 6;
const int selectled = 13;
int busypin = 7;
int volpin = A0;
const int track1led = A3;
const int track2led = A4;
const int track3led = A5;
int statechange = 0;
int statechangeOldState = 0;
int playerstate = 0;
int buttonStateoff = 0;
int buttonStatetrack1 = 0;
int buttonStatetrack2 = 0;
int buttonStatetrack3 = 0;
int volumelevel = 0;
/*************************************************************************
* these values will have to be changed if using another remote control *
*************************************************************************/
#define POWER 0x00FFA25D
#define A 0x00FF30CF
#define B 0x00FF18E7
#define C 0x00FF7A85
#define VOLUP 0x00FF629D
#define VOLDOWN 0x00FFA857
/*****************************************************
* put code here for intial set up and to run once *
*****************************************************/
void setup() {
Serial.begin(9600);
pinMode(busypin, INPUT);
pinMode(selectionSW,INPUT);
pinMode(buttonoff,INPUT);
pinMode(buttontrack1,INPUT);
pinMode(buttontrack2,INPUT);
pinMode(buttontrack3,INPUT);
pinMode(selectled,OUTPUT);
pinMode(track1led,OUTPUT);
pinMode(track2led,OUTPUT);
pinMode(track3led,OUTPUT);
mySoftwareSerial.begin(9600);
//Serial.begin(9600);
Serial.println(F("Initializing DFPlayer..."));
Serial.println(F("(may take 3 - 5 seconds)"));
delay(500);
Serial.println();
if (!myDFPlayer.begin(mySoftwareSerial)) {
Serial.println(F("Unable to begin."));
Serial.println(F("Please recheck all connection"));
Serial.println(F("Check the SD card"));
while (true);
}
Serial.println(F("Mini Player Online"));
myDFPlayer.setTimeOut(2000);
myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
myDFPlayer.enableDAC();
//irrecv.enableIRIn();
IrReceiver.begin(RECV_PIN, _LED_FEEDBACK);
}
/********************************************
* put the main code here to run repeatedly *
********************************************/
void loop() {
statechange = digitalRead(selectionSW);
if(statechange != statechangeOldState){
if(statechange == true){
Serial.println("state changed to manual");
resetcon();
}
else{
Serial.println("state changed to remote");
myDFPlayer.volume(15);
resetcon();
}
statechangeOldState = statechange;
}
if(statechange == true){
digitalWrite(selectled,HIGH);
manual();
}
else{
digitalWrite(selectled,LOW);
remote();
}
//playcon();
}
/********************************************
* put functions to be called and executed. *
********************************************/
/************************************************************
* following function is for the manual control when called *
************************************************************/
void manual(){
volumelevel = map(analogRead(volpin), 0 , 1023, 0 , 30);
myDFPlayer.volume(volumelevel);
buttonStateoff = digitalRead(buttonoff);
buttonStatetrack1 = digitalRead(buttontrack1);
buttonStatetrack2 = digitalRead(buttontrack2);
buttonStatetrack3 = digitalRead(buttontrack3);
if(buttonStateoff == HIGH){
digitalWrite(track1led,LOW);
digitalWrite(track2led,LOW);
digitalWrite(track3led,LOW);
myDFPlayer.pause();
}
else if(buttonStatetrack1 == HIGH){
digitalWrite(track1led,HIGH);
digitalWrite(track2led,LOW);
digitalWrite(track3led,LOW);
myDFPlayer.play(1);
}
else if(buttonStatetrack2 == HIGH){
digitalWrite(track1led,LOW);
digitalWrite(track2led,HIGH);
digitalWrite(track3led,LOW);
myDFPlayer.play(2);
}
else if(buttonStatetrack3 == HIGH){
digitalWrite(track1led,LOW);
digitalWrite(track2led,LOW);
digitalWrite(track3led,HIGH);
myDFPlayer.play(3);
}
delay(250);
}
/*****************************************************************
* following function is for the remote control side when called *
*****************************************************************/
void remote(){
/*if (irrecv.decode(&results)){
// Serial.println(results.value,HEX);
key_value = results.value;
delay(250);
switch (key_value){
case POWER:
digitalWrite(track1led,LOW);
digitalWrite(track2led,LOW);
digitalWrite(track3led,LOW);
myDFPlayer.pause();
delay(250);
//Serial.println("remotely selected Player Stopped");
break;
case A:
digitalWrite(track1led,HIGH);
digitalWrite(track2led,LOW);
digitalWrite(track3led,LOW);
myDFPlayer.play(1);
delay(250);
// Serial.println("remotely selected Track 1 playing");
break;
case B:
digitalWrite(track1led,LOW);
digitalWrite(track2led,HIGH);
digitalWrite(track3led,LOW);
myDFPlayer.play(2);
delay(250);
//Serial.println("remotely selected Track 2 playing");
break;
case C:
digitalWrite(track1led,LOW);
digitalWrite(track2led,LOW);
digitalWrite(track3led,HIGH);
myDFPlayer.play(3);
delay(250);
//Serial.println("remotely selected Track 3 playing");
break;
case VOLUP:
myDFPlayer.volumeUp();
break;
case VOLDOWN:
myDFPlayer.volumeUp();
break;
}
delay(250);
}*/
//if (irrecv.decode(&results)){
if(IrReceiver.decode()){
Serial.println(IrReceiver.decodedIRData.decodedRawData , HEX);
//if(results.value == POWER){
if(IrReceiver.decodedIRData.decodedRawData == POWER){
digitalWrite(track1led,LOW);
digitalWrite(track2led,LOW);
digitalWrite(track3led,LOW);
myDFPlayer.pause();
}
//else if(results.value == A){
else if(IrReceiver.decodedIRData.decodedRawData == A){
digitalWrite(track1led,HIGH);
digitalWrite(track2led,LOW);
digitalWrite(track3led,LOW);
myDFPlayer.play(1);
}
//else if(results.value == B){
else if(IrReceiver.decodedIRData.decodedRawData == B){
digitalWrite(track1led,LOW);
digitalWrite(track2led,HIGH);
digitalWrite(track3led,LOW);
myDFPlayer.play(2);
}
//else if(results.value == C){
else if(IrReceiver.decodedIRData.decodedRawData == C){
digitalWrite(track1led,LOW);
digitalWrite(track2led,LOW);
digitalWrite(track3led,HIGH);
myDFPlayer.play(3);
}
// else if(results.value == VOLUP){
else if(IrReceiver.decodedIRData.decodedRawData == VOLUP){
myDFPlayer.volumeUp();
}
//else if(results.value == VOLDOWN){
else if(IrReceiver.decodedIRData.decodedRawData == VOLDOWN){
myDFPlayer.volumeDown();
}
delay(250);
}
//irrecv.resume();
IrReceiver.resume();
}
/************************************************************************
* following function is to reset the mini player and visual conditions *
************************************************************************/
void resetcon(){
digitalWrite(track1led,LOW);
digitalWrite(track2led,LOW);
digitalWrite(track3led,LOW);
myDFPlayer.pause();
delay(250);
//Serial.println("Player reset and Stopped");
}
/*void playcon(){
playerstate = digitalRead(busypin);
if (playerstate == HIGH){
digitalWrite(track1led,LOW);
digitalWrite(track2led,LOW);
digitalWrite(track3led,LOW);
}
}*/