Noise on teensy 3.2 with audio adapter when using digitalRead

Status
Not open for further replies.

Gram

New member
Hello,

So I am running into a problem with my project. I hear a lot of noise when using the digitalRead as the cue to play a sound. I am using mpr121 capacitive touch sensors to get input from the user. An arduino uno is interpreting which pins have been touch and sending a digital high signal to the teensy 3.2 to play the corresponding sound. The sounds do play when the touch is detected but there is a beep that is playing over them and persist if the touch sensor is held. I am using a modified version of the sample player example with digitalRead instead of buttons.


I have the arduino, capacitive touch, and teensy all wired to the same ground. Any solutions to this problem would be greatly appreciated.





Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SerialFlash.h>
#include <Bounce.h>

// WAV files converted to code by wav2sketch
#include "AudioSampleSnare.h"        // http://www.freesound.org/people/KEVOY/sounds/82583/
#include "AudioSampleTomtom.h"       // http://www.freesound.org/people/zgump/sounds/86334/
#include "AudioSampleHihat.h"        // http://www.freesound.org/people/mhc/sounds/102790/
#include "AudioSampleKick.h"         // http://www.freesound.org/people/DWSD/sounds/171104/
#include "AudioSampleGong.h"         // http://www.freesound.org/people/juskiddink/sounds/86773/
#include "AudioSampleCashregister.h" // http://www.freesound.org/people/kiddpark/sounds/201159/

// Create the Audio components.  These should be created in the
// order data flows, inputs/sources -> processing -> outputs
//
AudioPlayMemory    sound0;
AudioPlayMemory    sound1;  // six memory players, so we can play
AudioPlayMemory    sound2;  // all six sounds simultaneously
AudioPlayMemory    sound3;
AudioPlayMemory    sound4;
AudioPlayMemory    sound5;
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 c2(sound1, 0, mix1, 1);
AudioConnection c3(sound2, 0, mix1, 2);
AudioConnection c4(sound3, 0, mix1, 3);
AudioConnection c5(mix1, 0, mix2, 0);   // output of mix1 into 1st input on mix2
AudioConnection c6(sound4, 0, mix2, 1);
AudioConnection c7(sound5, 0, mix2, 2);
AudioConnection c8(mix2, 0, headphones, 0);
AudioConnection c9(mix2, 0, headphones, 1);
AudioConnection c10(mix2, 0, dac, 0);

// Create an object to control the audio shield.
// 
AudioControlSGTL5000 audioShield;

  int val0 = 0;
  int val1=0;
  int val2= 0;
  int val3= 0;
  int val4=0;
  

void setup() {


  pinMode(0, INPUT_PULLDOWN);
  pinMode(1, INPUT_PULLDOWN);
  pinMode(2, INPUT_PULLDOWN);
  pinMode(3, INPUT_PULLDOWN);
  pinMode(4, INPUT_PULLDOWN);
  pinMode(5, INPUT_PULLDOWN);

  // 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);
  mix1.gain(1, 0.4);
  mix1.gain(2, 0.4);
  mix1.gain(3, 0.4);
  mix2.gain(1, 0.4);
  mix2.gain(2, 0.4);


}

void loop() {

  val0=digitalRead(2);
  val1=digitalRead(3);
  val2=digitalRead(4);
  val3=digitalRead(5);
  val4=digitalRead(6);
  
  
  if (val0 == true) {
    sound0.play(AudioSampleSnare);
  }
  if (val1 == true) {
    sound1.play(AudioSampleTomtom);
  }
  if (val2 == true) {
    sound2.play(AudioSampleHihat);
  }
  if (val3 == true) {
    sound3.play(AudioSampleKick);
  }
  if (val4 == true) {
    
    sound4.play(AudioSampleGong);
  }


}
 
Status
Not open for further replies.
Back
Top