Hello,
I am using Arduino Uno with Music Shield V2 and i want to control it with my infrared remote control.
I have some problems calling the functions in Music Player with my program, can anybody give me a hint please ?!?!
“”
#include <SD.h>
#include <SPI.h>
#include <arduino.h>
#include <MusicPlayer.h>
#include <IRremote.h>
const int sensorPin = A0;
long voltage, cm;
int sum=0;
int average=10;
//int delayTime = 450;//pauza intre aprinderea ledurilor
int LED1 = 3;
int LED2 = 4;
int LED3 = 5;
int LED4 = 6;
int LED5 = 7;
int LED6 = 8;
int LED7 = 9;
int LED8 = 10;
int LED9 = 2;
int IRpin = 11;
IRrecv irrecv(IRpin);
decode_results results;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
irrecv.enableIRIn();
player.begin(); //will initialize the hardware and set default mode to be normal.
player.setPlayMode(PM_SHUFFLE_PLAY); //set mode to play shuffle
player.scanAndPlayAll();
}
void loop() {
// put your main code here, to run repeatedly:
if (irrecv.decode(&results))
{
irrecv.resume(); // Receive the next value
}
if (results.value == 16582903)
{
player.play();
}
}
void playNextSong() {
if (results.value == 16625743)
{player.opNextSong();}
}
void playPreviousSong() {
if (results.value == 2797147069)
{player.opPreviousSong();}
}
void sonar() {
for(int i = 0; i < average ; i++)
{
voltage = analogRead(sensorPin)/2;
sum += voltage;
delay(5);
}
cm = (sum/average) * 2.54;
Serial.print("Distanta: ");
Serial.print(cm);
Serial.println(“cm”);
sum = 0;
if (cm < 100 )
{player.play();}
}
void volumeUp()//User-defined function
{
if (results.value == 46690913)
{player.opVolumeUp();}
}
void volumeDown()
{ if (results.value == 3001999165)
{ player.opVolumeDown() ;}}
void StopMusic() {
if (results.value == 3495072293)
{player.opStop();}
}
void playPause()//User-defined function
{if (results.value == 211564353)
{static boolean flag_on = 1;
if(flag_on) player.opPlay();
else player.opPause();
flag_on = !flag_on;
}}
“”
I can only call the “player.play” function, afterwards , there’s nothing i can do anymore.
Is there a problem calling the ctrlState ??
"
void setVolume(unsigned char volume) { vs1053.setVolume(volume, volume); _volume = volume;}
void adjustVolume(boolean UpOrDown, unsigned char NumSteps = 6);
void setPlayMode(playMode_t playmode) { _playmode = playmode;}
boolean deleteSong(char *songName);
void keyEnable(void) { Key_Disable = 0;}
void keyDisable(void) { Key_Disable = 1;}
void analogControlEnable(void) { Analog_Enable = 1;}
void digitalControlEnable(void) { Digital_Enable = 1;}
void play(void);
void midiDemoPlayer(void); //oliver wang
void opPlay(void) { playingState = PS_PLAY;}
void opPause(void) { playingState = PS_PAUSE;}
void opStop(void) { playingState = PS_IDLE;}
void opVolumeUp() {ctrlState = CS_UP;}
void opVolumeDown(void) { ctrlState = CS_DOWN;}
void opNextSong(void) { ctrlState = CS_NEXT;}
void opPreviousSong(void) { ctrlState = CS_PREV;}
"