Lights after Sound

Hello,

I am building a cake topper for my wedding and I just got some Adafruit Neopixel rings to do some lighting effects but Im having a problem getting the lights to work in my program. I have the lights working in a different sketch but when I try to add it I keep getting function-definition is not allowed here before "{" token errors. Im not sure why since it is set up exactly like the file that works. Here is the code that works

#include <Adafruit_NeoPixel.h>

#define PIN 53

// Parameter 1 = 24
// Parameter 2 = PIN
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(36, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.

void setup() {

strip.begin();
strip.show(); // Initialize all pixels to 'off'
}

void loop() {

delay(5000);

rainbow(150);
// rainbowCycle(20);
// theaterChaseRainbow(50);
}

// Fill the dots one after the other with a color
//void colorWipe(uint32_t c, uint8_t wait) {
// for(uint16_t i=0; i<strip.numPixels(); i++) {
// strip.setPixelColor(i, c);
// strip.show();
// delay(wait);
// }
//}

void rainbow(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}

and this is the code I have so far that will not work.

//MUSIC--------------------------------------------
// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// These are the pins used for the breakout example
#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)
// These are the pins used for the music maker shield
#define SHIELD_RESET -1 // VS1053 reset pin (unused!)
#define SHIELD_CS 7 // VS1053 chip select pin (output)
#define SHIELD_DCS 6 // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 4 // Card chip select pin
// DREQ should be an Int pin, see attachInterrupt() - Arduino Reference
#define DREQ 3 // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer =
// create breakout-example object!
//Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
// create shield-example object!
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

//Start Button-----------------------------------------
int inPin = 41; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status

//Interior Light----------------------------------------
int led = 28; // the pin that the Interior LED is attached to

//Motor Control------------------------------------------
int motorPin = 22;

//Sillohette Lights:-----------------------------------
#include <Adafruit_NeoPixel.h>
#define PIN 53
Adafruit_NeoPixel strip = Adafruit_NeoPixel(36, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

//Start Button Input :----------------------------------
pinMode(inPin, INPUT); // declare pushbutton as input

//Interior LED Setup:-----------------------------------
pinMode(led, OUTPUT);

//Motor Control:--------------------------------------
pinMode(motorPin, OUTPUT);

//MUSIC----------------------------------------------
Serial.begin(9600);
Serial.println("Adafruit VS1053 Library Test");

// initialise the music player
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"));

if (!SD.begin(CARDCS)) {
Serial.println(F("SD failed, or not present"));
while (1); // don't do anything more
}
Serial.println("SD OK!");

// list files
printDirectory(SD.open("/"), 0);

// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(1,1);

if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT))
Serial.println(F("DREQ pin is not an interrupt pin"));

//Sillohette Lights:-----------------------------------
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}

void loop() {

//Interior LED
digitalWrite(led, 255);

//Start Button Execution
val = digitalRead(inPin); // read input value
if (val > 0) { // check if the input is HIGH (button released)

//Motor Control:--------------------------
delay(1000);
digitalWrite(motorPin, HIGH);

// Alternately, we can just play an entire file at once
// This doesn't happen in the background, instead, the entire
// file is played and the program will continue when it's done!
musicPlayer.playFullFile("WedTop1.ogg");

// Start playing a file, then we can do stuff while waiting for it to finish
if (! musicPlayer.startPlayingFile("WedTop1.mp3")) {
Serial.println("Could not open file WedTop1.mp3");
while (1);
}
Serial.println(F("Started playing"));

while (musicPlayer.playingMusic) {
// file is now playing in the 'background' so now's a good time
// to do something else like handling LEDs or buttons :slight_smile:
Serial.print(".");

{

delay(54000);
rainbow(150);
}
void rainbow(uint8_t wait){
uint16_t i, j;

for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);

}
}
}

/// File listing helper
void printDirectory(File dir, int numTabs) {
while(true) {

File entry = dir.openNextFile();
if (! entry) {
// no more files
//Serial.println("nomorefiles");
break;
}
for (uint8_t i=0; i<numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs+1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}

}

}

can anyone give me a hand on this one? Thanks!

you should try to get that into code tags separating the different sketches.

Also, use auto format to clean up the code and you probably would benefit from getting rid of all that commentary. the experienced programmers here will know the code without needing the comments.

it is very hard to read the way you posted it.

Code Tags are created by pressing the hash (pound) button above the dialog box

I'm a novice but this part of the code looks wrong to me:

...

  while (musicPlayer.playingMusic) {
    // file is now playing in the 'background' so now's a good time
    // to do something else like handling LEDs or buttons :)
    Serial.print(".");
   
 
 {
 
   delay(54000);
   rainbow(150);
 }
missing a } here   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
void rainbow(uint8_t wait){ 
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();

I actually think the one { above delay is supposed to be a } instead of that last } being missing.

Qdeathstar:
I actually think the one { above delay is supposed to be a } instead of that last } being missing.

No. The one above the delay() statement is useless, and should be deleted, resulting in the correct number of { and }.