- Sun Feb 26, 2017 8:47 am
#193616
Hello!
I have a small problem, and when I try to throw an interrupt from the coin acceptor and to play an mp3, it only plays one second of the audio and stops, as if it only works well while releasing the pulse and then it freezes everything. I put the code I'm using, to see if anyone could help me:
I have a small problem, and when I try to throw an interrupt from the coin acceptor and to play an mp3, it only plays one second of the audio and stops, as if it only works well while releasing the pulse and then it freezes everything. I put the code I'm using, to see if anyone could help me:
Code: Select all
Thanks!!#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
SdFat sd;
SFEMP3Shield MP3player;
int calibrationTime = 10;
uint32_t offset = 0;
char trackName[] = "track.mp3";
const int coinpin = 0;
const int targetcents = 100;
volatile int cents = 0;
int credits = 0;
// Setup
void setup() {
Serial.begin(9600);
//start the shield
sd.begin(SD_SEL, SPI_HALF_SPEED);
MP3player.begin();
Serial.begin(9600);
attachInterrupt(0, coinInterrupt, RISING);
}
// Main loop
void loop() {
if (cents >= 1) {
if(!MP3player.isPlaying()){
MP3player.playMP3(trackName);
}
}
}
// Interrupt
void coinInterrupt(){
cents = cents + 1;
}