So, I've taken the wav playback example code and implemented it into my own project. what I'm using it for is a .wav sound is played when a push button is pushed (I've also got some neopixel lights that shine along with this). This all works perfectly, however my issue is, it only works when the serial monitor is open (lights don't turn on either until the monitor is open), I know why its opening and I think I know why the code is dependent on it. I just don't know how to fix it. And honestly I don't know any other way to play the sound files without the current code I have. I need this to work without being connected to my computer. This is also the first code I've ever written and forum post as well, so I'm very sorry if something is just ludicrously wrong.
I'm also using a MKRZERO
#include <Adafruit_NeoPixel.h>
#define LED_PIN2 A2
#define LED_PIN A3
#define LED_COUNT 8
#define LED_COUNT2 8
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2(LED_COUNT2, LED_PIN2, NEO_GRB + NEO_KHZ800);
#include <SD.h>
#include <ArduinoSound.h>
const int sPin = A6;
const int bPin = 5;
int v =0;
const char filename[] = "fire.WAV";
SDWaveFile waveFile;
void setup() {
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// setup the SD card, depending on your shield of breakout board
// you may need to pass a pin number in begin for SS
Serial.print("Initializing SD card...");
if (!SD.begin()) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// create a SDWaveFile
waveFile = SDWaveFile(filename);
// check if the WaveFile is valid
if (!waveFile) {
Serial.println("wave file is invalid!");
while (1); // do nothing
}
}
strip.begin();
strip2.begin();
strip.show();
strip2.show();
pinMode(LED_PIN, OUTPUT);
pinMode(LED_PIN2, OUTPUT);
pinMode(bPin, INPUT);
pinMode(sPin, OUTPUT);
}
void loop() {
v = digitalRead(bPin);
if (v == HIGH)
{
AudioOutI2S.play(waveFile);
AudioOutI2S.volume(1);
}else {
AudioOutI2S.volume(0);
}
uint32_t green = strip.Color(0, 200, 50);
uint32_t greener = strip.Color(0, 255, 0);
{
strip2.fill(blue, 0, 8);
strip2.setBrightness(100);
strip2.show();
delay(100);
strip2.setBrightness(0);
strip2.show();
delay(100);
strip2.setBrightness(100);
strip2.show();
}
{
strip.fill(blue, 0, 5);
strip.setBrightness(100);
strip.show();
delay(50);
strip.setBrightness(0);
strip.show();
delay(50);
strip.setBrightness(100);
strip.show();
strip.fill(white, 5, 8);
strip.setBrightness(100);
strip.show();
delayMicroseconds(30000);
strip.setBrightness(0);
strip.show();
delayMicroseconds(40000);
strip.setBrightness(100);
strip.show();
}
}```