Hello all. I working on a project that uses the mux-shield for additional inputs (up to 48). The general setup is simple each input pin has a piezo sensor that when pressed triggers a specific midi note as well as lights an LED. That part of the sketch works. Now I trying to add mp3 samples, one per sensor. I have the Geeetech MP3shield setup using the SFEMP3 library, audio files loaded on the SD card. So the big question is how do i code for it?
first step:
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
SFEMP3Shield MP3player;
then something like (this is the part I need help with)
mp3tone=0, mp3tone=<16, mp3tone++;
if(analogPin==0)
{
if (activePad[pad])
MP3player.playTrack(pad);
else
MP3player.playTrack(0);
}
The initial state is No Track Playing 0,
when one of the sensors are active the corresponding mp3 should play, when no pad is active no mp3 plays
Do i have to list all the mp3s in a array in the sketch?
Please find the code as it stands now attached. (MP3 part not yet added)
I realise some changes will need to be made to the pin config as the mp3shield needs D pin 2, so I'll change the mux control pins to 3,4,5,10 instead of ,2,3,4,5. I still have to check if there are pin conflicts between the I2c bus i.e. MCP port expander which drive the LEDs and the mp3shield. But for now I'm more focused on the software setup than the hardware.
pondering.......
mux0array = analogRead(0);
> You put the value of what is on the analogue port into a variable, the actual one depends on the value of i. It is like saying put this letter into the door number i in the street called mux0array, so as the value of i changes so you change the door where you post ( store ) the value.
* *for (int i=0; i<16; i++) { if(analogPin==0) { if (activePad[pad]) MP3Player.PlayTrack(Pad[i]); else MP3player.stopTrack(); }* *
==============================
Any help would be greatly appreciated
Thanks much
Caesar
scaledup_CC_mcp_ada_II_c_senitivity_retuneMOD_5.ino (9.14 KB)
button_player_Example GitHub - madsci1016/Sparkfun-MP3-Player-Shield-Arduino-Library: A nice and neat library for playing MP3s on your Arduino using Sparkfun's MP3 Player Shield
/**
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
#include <Bounce2.h>
#define B_NEXT A0
#define B_STOP A1
#define B_PLAY A2
#define BUTTON_DEBOUNCE_PERIOD 20 //ms
SdFat sd;
SFEMP3Shield MP3player;
Bounce b_Next = Bounce();
Bounce b_Stop = Bounce();
Bounce b_Play = Bounce();
/**
* \brief Index of the current track playing.
*
* Value indicates current playing track, used to populate "x" for playing the
* filename of "track00x.mp3" for track000.mp3 through track254.mp3
*/
int8_t current_track = 0;
void setup() {
Serial.begin(115200);
pinMode(B_NEXT, INPUT_PULLUP);
pinMode(B_STOP, INPUT_PULLUP);
pinMode(B_PLAY, INPUT_PULLUP);
b_Next.attach(B_NEXT);
b_Next.interval(BUTTON_DEBOUNCE_PERIOD);
b_Stop.attach(B_STOP);
b_Stop.interval(BUTTON_DEBOUNCE_PERIOD);
b_Play.attach(B_PLAY);
b_Play.interval(BUTTON_DEBOUNCE_PERIOD);
if(!sd.begin(9, SPI_HALF_SPEED)) sd.initErrorHalt();
if (!sd.chdir("/")) sd.errorHalt("sd.chdir");
MP3player.begin();
MP3player.setVolume(10,10);
}
void loop() {
// Below is only needed if not interrupt driven. Safe to remove if not using.
#if defined(USE_MP3_REFILL_MEANS) \
&& ( (USE_MP3_REFILL_MEANS == USE_MP3_SimpleTimer) \
|| (USE_MP3_REFILL_MEANS == USE_MP3_Polled) )
MP3player.available();
#endif
if (b_Play.update()) {
if (b_Play.read() == LOW) {
MP3player.playTrack(current_track);
}
}
if (b_Stop.update()) {
if (b_Stop.read() == LOW) {
MP3player.stopTrack();
}
}
if (b_Next.update()) {
if (b_Next.read() == LOW) {
MP3player.stopTrack();
MP3player.playTrack(current_track);
}
}
//Do something. Have fun with it.
}
Put the input buttons into an array. The first mux chip 16 inputs= mux0 the second mux1, third mux2..... Mux0 is analog pin1, mux1 pin2 and so on.
Now for the array of files. Much of the indexing is done by the library.
For now let call it FileArray0, FileArray1, FileArray2; the size of each=0-16
Now the index operator (variable) Call it FileToPlay
FtP=0; FtP=<16; Ftp++;
MuxArray= Street#
FtP=P.O.Box#
According to the examples in SFEMP3 player library. you can play a file using numbers 0-9 but the can play up to 255 files.
/**
- \brief Index of the current track playing.
- Value indicates current playing track, used to populate "x" for playing the
- filename of "track00x.mp3" for track000.mp3 through track254.mp3
*/
int8_t current_track = 0;
My question is how do I call up a specific track by number, for not just 0 thru 9 but lets say #25 of 36?
From reading the example and library files it seems that by number would be easier than by filename.
I've tried a few things, like:
for (int i=0; 1<16; 1++)
if (analogPin==0) {
if(activePad[pad]
MP3player.playTrack(current_track[i]);
eles
MP3player.stopTrack();
but nothing works, or even complies that this point.
Any thoughts?