Go Down

Topic: sd card plus 2 buttons (Read 283 times) previous topic - next topic


hi. I need some help on some coding.
I have a code, which is similar to what I want done

Code: [Select]
Arduino Based Music Player
 This example shows how to play three songs from SD card by pressing a push button
 The circuit:
 * Push Button on pin 2 and 3
 * Audio Out - pin 9
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 created  25 Jun 2017
 This example code was created for CircuitDigest.com
#include "SD.h" //Lib to read SD card
#include "TMRpcm.h" //Lib to play auido
#include "SPI.h" //SPI lib for SD card
#define SD_ChipSelectPin 4 //Chip select is pin number 4
TMRpcm music; //Lib object is named "music"
int song_number=0;
boolean debounce1=true;
boolean debounce2=true;
boolean play_pause;
void setup(){
music.speakerPin = 9; //Auido out on pin 9
Serial.begin(9600); //Serial Com for debugging
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
pinMode(2, INPUT_PULLUP); //Button 1 with internal pull up to chage track
pinMode(3, INPUT_PULLUP); //Button 2 with internal pull up to play/pause
pinMode(3, INPUT_PULLUP); //Button 2 with internal pull up to fast forward
music.setVolume(5);    //   0 to 7. Set volume level
music.quality(1);        //  Set 1 for 2x oversampling Set 0 for normal
//music.volume(0);        //   1(up) or 0(down) to control volume
//music.play("filename",30); plays a file starting at 30 seconds into the track   
void loop()
  if (digitalRead(2)==LOW  && debounce1 == true) //Button 1 Pressed
  if (song_number==5)
  Serial.println("KEY PRESSED");
  if (song_number ==1)
  {music.play("1.wav",10);} //Play song 1 from 10th second
  if (song_number ==2)
  {music.play("2.wav",33);} //Play song 2 from 33rd second
  if (song_number ==3)
  {music.play("3.wav");} //Play song 3 from start
  if (song_number ==4)
  {music.play("4.wav",25);} //Play song 4 from 25th second
  if (digitalRead(3)==LOW  && debounce2 == true) //Button 2 Pressed
  music.pause();  Serial.println("PLAY / PAUSE");
  if (digitalRead(2)==HIGH) //Avoid debounce
  if (digitalRead(3)==HIGH)//Avoid debounce

however I want change the buttons.
I want one to play one single track and the other button to play about 8 tracks. they are all a few seconds.

I have tried to change some coding but I keep getting errors. I am new to this and would be grateful if someone can put me in the right direction
thanks for any help given.


Please format your code before posting (autoformat in the IDE is doing a great job - press ctrl-T).

Then, what errors do you get?
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up