So I programmed my Arduino Mega 2560 to play certain sound effects from a DF Mini Player that I have. I took the base code that I modified from online so some fo the names might seem odd. Currently, when uploaded to the Arudino, it works as it should, "buttonPause" and "play()" only play one of the audio files WHILE I am pressing a button. "buttonNext"/"play1()" and "buttonPrevious"/"play2()" activate a sound when a button is tapped (not held down). To allow the sound effect to play in full only while I'm, holding down "buttonPause," I had to use a delay as well as interrupt to stop the playback as soon as I released the button. However, I know aside from changing pin numbers, there are some other alterations I have to make for the interrupt to adapt it to work with the ATTiny85. Any idea how I can get started on making those changes? I have been confused by the sources I have found online.

Full code for using the DF Mini Player with the Arduino Mega

///              MP3 PLAYER PROJECT
/// http://educ8s.tv/arduino-mp3-player/
#include "SoftwareSerial.h"
SoftwareSerial mySerial(10, 11);
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]

int buttonNext = 2;
int buttonPause = 3;
int buttonPrevious = 4;
boolean isPlaying = false;
const byte interruptPin = 3;
volatile byte state = LOW;
int buttonState = 0;
int buttonState1= 0;
int buttonState2= 0;
int ledPin = 9;

void setup () {
pinMode(buttonPause, INPUT);
pinMode(buttonNext, INPUT);
pinMode(buttonPrevious, INPUT);
mySerial.begin (9600);
attachInterrupt(digitalPinToInterrupt(interruptPin), pause, CHANGE);
pinMode(ledPin, OUTPUT);

void loop () { 

buttonState = digitalRead(buttonPause);
buttonState1 = digitalRead(buttonNext);
buttonState2 = digitalRead(buttonPrevious);

if (buttonState == LOW)
      setColor(255, 0, 222); // red
      digitalWrite(ledPin, HIGH);


if (buttonState1 == HIGH)


if (buttonState == HIGH)


  if (buttonState1 == LOW)



if (buttonState2 == HIGH)


    if (buttonState2 == LOW)



void pause()

      digitalWrite(ledPin, LOW);
void play()
void play1()
void play2()


void execute_CMD(byte CMD, byte Par1, byte Par2)
// Excecute the command and parameters
// Calculate the checksum (2 bytes)
word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
// Build the command line
byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
//Send the command line to the module
for (byte k=0; k<10; k++)
mySerial.write( Command_line[k]);

Board Layout

The amount and placements of the resistors seemed to reduce the amount of noise as much as possible.


  • why do you need to use an interrupt? – jsotola Jul 16 '19 at 5:01
  • So that when I release "buttonPause" it immediately interrupts the delay (that allows it to play through without moving to the next audio clip) and stops the playblack. I attempted to use millis instead of delay and interrupt to avail. – Ryan F Jul 16 '19 at 5:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.