I. AM. A. NOOB.
I'm missing something very basic and stupid here I know but I would love it if somebody could point that error out.
Code is below. TEENSY3.1 using the TEENSY audio shield. Behavior right now: it almost randomly plays the audio file but skips over the relays. It won't stop! Stooopid something there. Here you go, let's see who spots it first TIA
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Bounce.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(0, 5);
//setting up relays
int fan = 23;
int heat = 21;
int wled = 19;
int bled = 17;
void setup() {
// Configure the pushbutton pins for pullups.
// Each button should connect from the pin to GND.
pinMode(0, INPUT_PULLUP);
// 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);
}
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
if (button0.risingEdge()) {
sound0.play(AudioSampleClap_r1); //sound starts
delay(100); // wait for 100 ms
digitalWrite(fan, HIGH); // turn the fan on (HIGH is the voltage level)
delay(100); // wait for 100 ms
digitalWrite(heat, HIGH); // turn the heat on
delay(10); // wait for 10 ms
digitalWrite(wled, HIGH); //bright white LEDs on
delay(25);
digitalWrite(bled, HIGH); //bright white LEDs on
delay(25);
digitalWrite(bled, LOW);
delay(25);
digitalWrite(wled, LOW);
}
else {
// turn everything off:
digitalWrite(wled, LOW);
digitalWrite(bled, LOW);
digitalWrite(fan, LOW);
digitalWrite(heat, LOW);
}
delay(1000);
}
I'm missing something very basic and stupid here I know but I would love it if somebody could point that error out.
Code is below. TEENSY3.1 using the TEENSY audio shield. Behavior right now: it almost randomly plays the audio file but skips over the relays. It won't stop! Stooopid something there. Here you go, let's see who spots it first TIA
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Bounce.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(0, 5);
//setting up relays
int fan = 23;
int heat = 21;
int wled = 19;
int bled = 17;
void setup() {
// Configure the pushbutton pins for pullups.
// Each button should connect from the pin to GND.
pinMode(0, INPUT_PULLUP);
// 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);
}
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
if (button0.risingEdge()) {
sound0.play(AudioSampleClap_r1); //sound starts
delay(100); // wait for 100 ms
digitalWrite(fan, HIGH); // turn the fan on (HIGH is the voltage level)
delay(100); // wait for 100 ms
digitalWrite(heat, HIGH); // turn the heat on
delay(10); // wait for 10 ms
digitalWrite(wled, HIGH); //bright white LEDs on
delay(25);
digitalWrite(bled, HIGH); //bright white LEDs on
delay(25);
digitalWrite(bled, LOW);
delay(25);
digitalWrite(wled, LOW);
}
else {
// turn everything off:
digitalWrite(wled, LOW);
digitalWrite(bled, LOW);
digitalWrite(fan, LOW);
digitalWrite(heat, LOW);
}
delay(1000);
}