cyclpsrock
Member
Hey, not sure what's going on here, I have a 3.2 with soldered audio shield on a breadboard. My code works, but if I am to unplug the USB cable and plug it back in, audio stops working. I can tell the code is still working because the LED lights when I press the button, but no sound. The workaround I've found is to load the Audio > Synthesis > Waveforms example sketch which will cause a "pop" and the audio comes back, then I am able to load my own project back in and it works. Pretty strange!
Seems like possibly not code-related but I'll include it anyway. It just triggers an FM synth drum and lights the LED from a button press.
Seems like possibly not code-related but I'll include it anyway. It just triggers an FM synth drum and lights the LED from a button press.
Code:
//LIBRARIES
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
// GUItool: begin automatically generated code
AudioSynthWaveform FMwaveform1; //xy=77,500
AudioSynthWaveformSine FMsine2; //xy=78,374
AudioSynthWaveformSine FMsine1; //xy=92,320
AudioSynthWaveformModulated FMwaveformMod1; //xy=91.5,550
AudioMixer4 mixer_FM; //xy=235,432
AudioSynthWaveformSineModulated sine_fm1; //xy=372,433
AudioEffectEnvelope FM1envelope; //xy=628,430
AudioMixer4 mixer_R; //xy=775,483
AudioMixer4 mixer_L; //xy=777,368
AudioOutputI2S aux_out; //xy=897,400
AudioConnection patchCord1(FMwaveform1, 0, mixer_FM, 2);
AudioConnection patchCord2(FMsine2, 0, mixer_FM, 1);
AudioConnection patchCord3(FMsine1, 0, mixer_FM, 0);
AudioConnection patchCord4(FMwaveformMod1, 0, mixer_FM, 3);
AudioConnection patchCord5(mixer_FM, sine_fm1);
AudioConnection patchCord6(sine_fm1, FM1envelope);
AudioConnection patchCord7(FM1envelope, 0, mixer_L, 3);
AudioConnection patchCord8(FM1envelope, 0, mixer_R, 0);
AudioConnection patchCord9(mixer_R, 0, aux_out, 1);
AudioConnection patchCord10(mixer_L, 0, aux_out, 0);
// GUItool: end automatically generated code
const int led = 13;
const int bdelay = 15; // (orig 10-15) bounce delayy
Bounce butt = Bounce(0, bdelay); //ARCADE BUTTON
void setup() {
pinMode(led, OUTPUT);
pinMode(0, INPUT_PULLUP); //ARCADE BUTTON
Serial.begin(115200);
// audio library init
AudioMemory(15);
AudioNoInterrupts();
FMsine1.frequency(.5);
FMsine1.amplitude(.1);
FMsine2.frequency(800);
FMsine2.amplitude(0.3);
FMwaveform1.begin(0.3, 240, WAVEFORM_SAWTOOTH);
//FMwaveformMod1.begin(0.3, 5, WAVEFORM_SINE);
//FMwaveformMod1.frequencyModulation(12);
sine_fm1.frequency(80);
sine_fm1.amplitude(1);
FM1envelope.attack(1);
FM1envelope.hold(0);
FM1envelope.decay(500);
FM1envelope.sustain(0.0);
FM1envelope.release(500);
FM1envelope.releaseNoteOn(5);
AudioInterrupts();
}
void loop() {
butt.update();
if (butt.fallingEdge()){
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
FMsine1.phase(90);
FM1envelope.noteOn();
}
if (butt.risingEdge()){
digitalWrite(led, LOW); // turn the LED off (LOW is the voltage level)
FM1envelope.noteOff();
}
}