SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By Red_Fox
#183227
Hi everyone,
I just got the Mp3 trigger but the lack of example code out there is giving me fits. I am using this library in an attempt to try and simplify the commands: https://github.com/sansumbrella/MP3Trigger-for-Arduino. However, it doesn't have any worhwhile example code either. All i'm trying to do is use the serial connection to trigger some mp3s in my code. I get about one or two of my mp3s play at almost the right time, and then when I'm fading a strip of LEDs it plays the mp3s as the led commands are written. I'm using the serial monitor for trouble shooting the lighting.
Code: Select all
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#include <FastLED.h>
#include <MP3Trigger.h>
#define PIN 6
#define NUM_LEDS 44
CRGB leds[NUM_LEDS];
MP3Trigger trigger;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  trigger.setup(&Serial);
  Serial.begin( MP3Trigger::serialRate() );
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}
Code: Select all
 colorWipe2(strip.Color(32, 0, 128), 500); // blue
      delay (1000);
      trigger.play(1);
      trigger.update();
      Serial.println("track001");
      delay (500);
      //switch (random(1, 3)) {
      //switch (3) {
In case it isn't obvious I'm a novice at this sort of thing.
I've tried other bits of example code by themselves and can't make them work either.
User avatar
By Ross Robotics
#183248
I am sure robertsonics (designer) will reply here shortly. But in the mean time, you can search "mp3 trigger" here and get some threads with the same question.
User avatar
By robertsonics
#183260
I'm not familiar with that particular library, but if I understand your description correctly, I would guess the problem is that you're trying to use the same serial port for both the MP3 Trigger and the serial monitor. At least that's what your code snippets imply.

You didn't say what Arduino you're using, but if you only have the one hardware serial port, then I suggest using the AltSoftSerial library to create an additional serial port using one of the standard digital pins, and use that for the MP3 Trigger.