Hi,
I want some guidance to write a piece of code. I am not expert in coding.
My gadget is Arduino atmega328 + LC Studio sd card breakout board.This gadget is to play wave audio files stored in the sd card.The wave files are numerically named as 0001.wav,0002.wav,0003.wav,....etc (they are 100s in numbers). I want to play these files as described below.
I want to have 2 push buttons(called UP,DOWN) connected to the interrupts pins 2 & 3 respectively.At start-up, file "0001.wav" should be played.When I press 'UP' button once, file "0002.wav" should be played.Consecutively pressing 'UP', files with increment in name (0003.wav,0004.wav....so on), should be played. The 'DOWN' button is meant for decrement order play,you figured it out,I guess.
So far my code is this.
#include <SD.h> // need to include the SD library
#define SD_ChipSelectPin 4 // using digital pin 4 on arduino nano 328, can use other pins
#include <TMRpcm.h> // also need to include this library...
TMRpcm tmrpcm; // create an object for use in this sketch
void setup(){
tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) { // see if the card is present and can be initialized:
Serial.println("SD fail");
return; // don't do anything more if not
}
pinMode(2,INPUT);
digitalWrite(2,HIGH);
attachInterrupt(0,otherfile,FALLING);
}
void loop(){
noInterrupts();
tmrpcm.play("0001.wav");
while(tmrpcm.isPlaying()) {}
interrupts();
}
void otherfile() {
noInterrupts();
delay(10); // clean switching
tmrpcm.play("0002.wav");
while(tmrpcm.isPlaying()) {}
}
I am successfuly played the start up file 0001.wav.I donot know how to proceed.I have tried interrupt service routine and able to play one of the remaining songs, though it is not a good way, as shown in the codes .How to go about this ?
I sought your help.
BTW, apart from the standard <SD.h> ,I'm using "tmrpcm" library found here.
https://github.com/TMRh20/TMRpcm
Thank you in advance.
manmachine