69Views1Replies

Author Options:

Music Shield crash Answered

Hey! I need a help, i used te Music Shield v2.0 With audio analyser v2.0.. I play  1 or 2 songs he crashes, why?
Sorry my english, im portuguese

this is code i used:

#include <SD.h>
#include <SPI.h>
#include <arduino.h>
#include <MusicPlayer.h>
int analogPin = 5; // MSGEQ7 OUT 3
int strobePin = 12; // MSGEQ7 STROBE 4
int resetPin = 11; // MSGEQ7 RESET 7
int spectrumValue[7];
// MSGEQ7 OUT pin produces values around 50-80
int filterValue = 65;

// 1 Bola
int bola1 = 23;
// 2 Bola
int bola2 = 24;
// 3 Bola
int bola3 = 25;
// 4 Bola
int bola4 = 26;
// 5 Bola
int bola5 = 27;
// 6 Bola
int bola6 = 28;
// 7 Bola
int bola7 = 29;

int Val1=0;
int Val2=0;
int Val3=0;
int Val4=0;
int Val5=0;
int Val6=0;
int Val7=0;

void setup()
{
  pinMode(bola1, OUTPUT);
  pinMode(bola2, OUTPUT);
  pinMode(bola3, OUTPUT);
  pinMode(bola4, OUTPUT);
  pinMode(bola5, OUTPUT);
  pinMode(bola6, OUTPUT);
  pinMode(bola7, OUTPUT);

  Serial.begin(9600);
  player.keyDisable(); //keys disable first;
  player.analogControlEnable(); //enable to scan the A4/A5
  player.begin(); //will initialize the hardware and set default mode to be normal.
  player.setPlayMode(PM_REPEAT_LIST); //set mode to repeat to play List
  player.attachAnalogOperation(A4, adjustVolume); //Grove - Rotary Angle Sensor connected to A4,to control the volume
  player.scanAndPlayAll(); //If the current playlist is empty,it will add all the songs in the root directory to the playlist.
  Serial1.begin(1200);
  pinMode(analogPin, INPUT);
  pinMode(strobePin, OUTPUT);
  pinMode(resetPin, OUTPUT);
  analogReference(DEFAULT);
  digitalWrite(resetPin, LOW);
  digitalWrite(strobePin, HIGH);

}

void loop(void)
{

// Set reset pin low to enable strobe
digitalWrite(resetPin, HIGH);
digitalWrite(resetPin, LOW);
// Get all 7 spectrum values from the MSGEQ7
for (int i = 0; i < 7; i++)
{
digitalWrite(strobePin, LOW);
delayMicroseconds(30); // Allow output to settle
spectrumValue[i] = analogRead(analogPin);
// Constrain any value above 1023 or below filterValue
spectrumValue[i] = constrain(spectrumValue[i], filterValue, 1023);
// Remap the value to a number between 0 and 255
spectrumValue[i] = map(spectrumValue[i], filterValue, 1023, 0, 255);
// Remove serial stuff after debugging
Serial.print(spectrumValue[i]);
Serial.print(" ");
digitalWrite(strobePin, HIGH);
}

Serial.println("Analisador de som");

// 1 Bola
if(spectrumValue[0]>150)
{
  Val1 =spectrumValue[0];
}
analogWrite(bola1, Val1);

if(spectrumValue[0]<110)
{
  Val1 =0;
}
analogWrite(bola1, Val1);

// 2 Bola
if(spectrumValue[1]>150)
{
  Val2 =spectrumValue[1];
}
analogWrite(bola2, Val2);

if(spectrumValue[1]<110)
{
  Val2 =0;
}
analogWrite(bola2, Val2);

// 3 Bola
if(spectrumValue[2]>150)
{
  Val3 =spectrumValue[2];
}
analogWrite(bola3, Val3);

if(spectrumValue[2]<110)
{
  Val3 =0;
}
analogWrite(bola3, Val3);

// 4 Bola
if(spectrumValue[3]>150)
{
  Val4 =spectrumValue[3];
}
analogWrite(bola4, Val4);

if(spectrumValue[3]<110)
{
  Val4 =0;
}
analogWrite(bola4, Val4);

// 5 Bola
if(spectrumValue[4]>150)
{
  Val5 =spectrumValue[4];
}
analogWrite(bola5, Val5);

if(spectrumValue[4]<110)
{
  Val5 =0;
}
analogWrite(bola5, Val5);

// 6 Bola
if(spectrumValue[5]>150)
{
  Val6 =spectrumValue[5];
}
analogWrite(bola6, Val6);

if(spectrumValue[5]<110)
{
  Val6 =0;
}
analogWrite(bola6, Val6);

// 7 Bola
if(spectrumValue[6]>150)
{
  Val7 =spectrumValue[6];
}
analogWrite(bola7, Val7);

if(spectrumValue[6]<110)
{
  Val7 =0;
}
{
analogWrite(bola7, Val7);
Serial1.println("Music Shield");
}
player.play();
}
void adjustVolume(void) //User-defined function
{
unsigned int vol_temp = analogRead(A4);
unsigned char volume = vol_temp / 12;
{
if (volume == 0x55) volume = MAXVOL; //MAXVOL = 0xfe;
player.setVolume(volume);
}
}

Tags:Arduino

Discussions

0
None
gmoon

3 years ago

I don't know the source of your problems with the shield, but I have a few comments on the code:

-- Declare all the bolaX integer variables as constants, as they don't ever seem to have reassigned values after their declarations. The compiler might do this automatically, though, depending on it's ability to optimize.

-- Define one Val integer and reuse it. I don't see any reason for seven different ValX variables.

-- Not even sure you need Val variables at all:

// 4 Bola

if(spectrumValue[4]>150)
{ analogWrite(bola5, spectrumValue[4]); }

else if(spectrumValue[4]<110)
{ analogWrite(bola5, 0); }