Projet en lien avec la Web Radio Mobile (asbl BRAVVO – Bruxelles)

découpe laser + système arduino pour la diffusion du son.

MP3 shield -webradio
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)

#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

#define CARDCS 4     // Card chip select pin
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

const int led = 3, btn1 = 1, btn2 = 2, pota = 0; 
int volume = 20, nvPota,lastNvPota,i;

int maxTrack = 9;
char* songs[] = {"001.mp3","002.mp3","003.mp3","004.mp3","005.mp3","006.mp3","007.mp3","008.mp3","009.mp3"};

int songNumber = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("WebRadioMobile + Bru'Surf say u Hello :p");

  if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }
  Serial.println(F("VS1053 found- :) "));
  
  SD.begin(CARDCS);    // initialise the SD card
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(volume,volume);
  
  musicPlayer.GPIO_pinMode(led, OUTPUT);
  musicPlayer.GPIO_pinMode(btn1 , INPUT);
  musicPlayer.GPIO_pinMode(btn2, INPUT);

  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);

musicPlayer.startPlayingFile(songs[songNumber]);
Serial.println(songs[songNumber]);
musicPlayer.GPIO_digitalWrite(led, LOW);
}
void loop() {
  if (musicPlayer.GPIO_digitalRead(btn1) == HIGH) {

    prev();
    delay(500);
  };
  if (musicPlayer.GPIO_digitalRead(btn2) == HIGH) {
 
    next();
    delay(500);
  };
    nvPota = analogRead(pota);
  if (nvPota!=lastNvPota){
  nvPota = analogRead(pota);
  // Serial.println(nvPota);
  volume = map(nvPota,0,1000,1,80);
   musicPlayer.setVolume(volume,volume);
   Serial.println(volume);
 lastNvPota=nvPota;}
if (musicPlayer.stopped()){next() ;};
}
void LED() {
  Serial.print("led"); 
  for (i =0; i<songNumber+1;i++)
  {
  musicPlayer.GPIO_digitalWrite(led, HIGH);
  delay(200);
  musicPlayer.GPIO_digitalWrite(led, LOW);
  delay(200);
  Serial.print(i); 
  Serial.print('\t');
};
Serial.println(" ");
}
void prev() {
  if (songNumber - 1 > 0)
  {
    songNumber = songNumber - 1;
  }
  else
  {
    songNumber = maxTrack - 1;
  };
  Serial.print("prev ");
  Serial.println(songs[songNumber]);
  LED();
  musicPlayer.startPlayingFile(songs[songNumber]);

  delay(500);
}
void next() {
  if (songNumber + 1 < maxTrack)
  {
    songNumber = songNumber + 1;
  }
  else
  {
    songNumber = 0;
  };
    Serial.print("next ");
  Serial.println(songs[songNumber]);
    LED();
  musicPlayer.startPlayingFile(songs[songNumber]);
  delay(500);
}