OK guys, just knowing that those pins were dedicated to audio or wire or otherwise TAKEN (I don't feel too incredibly stupid now as it seems that should be pretty obviously noted on the audio shield info, no?) things started working. Michael your notes are gold.
Here's the working code:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Bounce.h>
#include <elapsedMillis.h>
// WAV files converted to code by wav2sketch
#include "AudioSampleClap_r1.h"
// Create the Audio components. These should be created in the
// order data flows, inputs/sources -> processing -> outputs
//
AudioPlayMemory sound0;
AudioMixer4 mix1; // two 4-channel mixers are needed in
AudioMixer4 mix2; // tandem to combine 6 audio sources
AudioOutputI2S headphones;
AudioOutputAnalog dac; // play to both I2S audio board and on-chip DAC
// Create Audio connections between the components
//
AudioConnection c1(sound0, 0, mix1, 0);
AudioConnection c8(mix1, 0, headphones, 0);
AudioConnection c9(mix1, 0, headphones, 1);
// Create an object to control the audio shield.
AudioControlSGTL5000 audioShield;
// Bounce objects to read six pushbuttons (pins 0-5)
Bounce button0 = Bounce(1, 1);
//setting up relays
int fan = 2;
int heat = 3;
int wled = 4;
int bled = 5;
//sequence variable, indicates which step we are in
int sequenceStep;
elapsedMillis timeElapsed;//global timing variable
void setup() {
// Configure the pushbutton pins for pullups.
// Each button should connect from the pin to GND.
pinMode(1, INPUT_PULLUP);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(10);
// turn on the output
audioShield.enable();
audioShield.volume(0.5);
// by default the Teensy 3.1 DAC uses 3.3Vp-p output
// if your 3.3V power has noise, switching to the
// internal 1.2V reference can give you a clean signal
//dac.analogReference(INTERNAL);
// reduce the gain on mixer channels, so more than 1
// sound can play simultaneously without clipping
mix1.gain(0, 0.4);
sequenceStep = 0;
}
void loop() {
// Update the button object
button0.update();
// When the button 0 is pressed, the sequence of events begins with sound, then fan,
// then heat, then lights flashing. THEN TURNS OFF and waits for button to be pushed again]
// Only start sequence if we finished the last one already
if (button0.fallingEdge() && sequenceStep == 0) {
sequenceStep = 1;
timeElapsed = 0;
}
//if 100 millis have passed since the first step go to step 2 (fan)
if (sequenceStep == 1 && timeElapsed >= 100) {
sequenceStep = 2;
timeElapsed = 0;
digitalWrite(fan, HIGH); // turn the fan on (HIGH is the voltage level)
}
// if 3000 millis have passed since step 2 turn on heat and play sound
if (sequenceStep == 2 && timeElapsed >= 3000) {
sequenceStep = 3;
timeElapsed = 0;
digitalWrite(heat, HIGH); // turn the heat on
sound0.play(AudioSampleClap_r1); //sound starts
}
// if 100 millis have passed turn on wled
if (sequenceStep == 3 && timeElapsed >= 3000) {
sequenceStep = 4;
timeElapsed = 0;
digitalWrite(wled, HIGH); //bright white LEDs on
}
// if 25 millis have passed turn on bled
if (sequenceStep == 4 && timeElapsed >= 2000) {
sequenceStep = 5;
timeElapsed = 0;
digitalWrite(bled, HIGH); //bright white LEDs on
}
// if 25 millis have passed turn off bled
if (sequenceStep == 5 && timeElapsed >= 2500) {
sequenceStep = 6;
timeElapsed = 0;
digitalWrite(bled, LOW); //bright white LEDs off
}
// if 25 millis have passed turn off wled
if (sequenceStep == 6 && timeElapsed >= 2500) {
sequenceStep = 7;
timeElapsed = 0;
digitalWrite(wled, LOW); //bright white LEDs off
}
// wait 500 millis and turn everything off and reset
if (sequenceStep == 7 && timeElapsed >= 13100) {
sequenceStep = 0;
timeElapsed = 0;
//these were already turned off above
digitalWrite(wled, LOW);
digitalWrite(bled, LOW);
digitalWrite(fan, LOW);
digitalWrite(heat, LOW);
}
}