I just buy the Cytron MP3 Shield but i have a issue when i use it with I2C (Wire standard library).
can i do that ? or they have some I2C are already use by the shield ?
My code :
- CODE: SELECT_ALL_CODE
#include <SdFat.h>
#include <MP3Player.h>
#include <Wire.h> // Librairie pour la communication I2C
//Declarations des entrées/sorties
//*********************************************************************
int dataMP3 = 2; //bus de données MP3
int clockMP3 = 3; //bus d'horloge MP3
int MP3Shield = A0; //Port MP3 A0
String Folder = "mp3";
int val = 0; // variable to store the value read
int vol = 220;
int state = -1;
int temps = 0;
int value = -1;
void setup()
{
//Initialisation MP3
pinMode(MP3Shield, INPUT);
randomSeed(analogRead(MP3Shield));
Serial.begin(9600);
if (!mp3.Init(clockMP3, dataMP3))
{
while (1);
}
vol = 220;
mp3.setVolume(220);
val = 0;
Wire.begin(4); // Rejoindre le bus à l'adresse #4
Wire.onReceive(receiveEvent); // Preparer une fonction spécifique a la reception de donnee
}
void loop()
{
delay(100);
if (state != value)
{
state = value;
Serial.println(">>>");
Serial.println(state);
switch (state)
{
case 0:
mp3.Stop();
break;
case 1:
mp3.PlayTrack("cloud", "1.mp3");
break;
case 2:
mp3.setVolume(++vol);
break;
case 3:
mp3.setVolume(--vol);
break;
case 4:
mp3.Next();
break;
case 5:
mp3.Previous();
break;
case 6:
if (mp3.isPlaying())
{
mp3.Stop();
}
else
{
mp3.PlayFolder(Folder.c_str());
}
break;
}
}
}
// Fonction qui s execute si quelque chose est present sur l interface
void receiveEvent(int howMany)
{
int x = Wire.read();
Serial.println(x);
switch (x)
{
case 0:
value = 0;
break;
case 1:
value = 1;
break;
case 2:
value = 2;
break;
case 3:
value = 3;
break;
case 4:
value = 4;
break;
case 5:
value = 5;
break;
case 6:
value = 6;
break;
}
}