herr-nielsson
Member
Hallo everyone,
as i'm new to programming, i got some (hopefully) little trouble to smooth the performance of my Teensy.
Hopefully somebody could help me solving this Problem:
The Code below plays four short sounds after pushing four buttons and it's working (yeah!). But i'd like them to be played kinda simultaneously. So when i push two buttons exactly in time, one sound will be not played. Same Story, another image: when the first sound (which has got a little reverb) is playing, it will be cut by pushing another button.
i hope, you got, what i'm after.
So any suggestion is appreciated!
Thanx a lot for help!!!
as i'm new to programming, i got some (hopefully) little trouble to smooth the performance of my Teensy.
Hopefully somebody could help me solving this Problem:
The Code below plays four short sounds after pushing four buttons and it's working (yeah!). But i'd like them to be played kinda simultaneously. So when i push two buttons exactly in time, one sound will be not played. Same Story, another image: when the first sound (which has got a little reverb) is playing, it will be cut by pushing another button.
i hope, you got, what i'm after.
So any suggestion is appreciated!
Thanx a lot for help!!!
Code:
// Teensy 3.2
// Arduino 1.8.5
// Teensyduino 1.4.2
// Mac Book Pro
// OSX 10.11.6
// Code built with help from the brilliant System Design Tool
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
AudioPlaySdWav playSdWav1; //xy=136,245
AudioPlaySdWav playSdWav2; //xy=165,292
AudioPlaySdWav playSdWav3; //xy=193,344
AudioPlaySdWav playSdWav4; //xy=212,390
AudioMixer4 mixer1; //xy=477,277
AudioOutputI2S i2s1;
AudioConnection patchCord1(playSdWav1, 0, mixer1, 0);
AudioConnection patchCord2(playSdWav2, 0, mixer1, 1);
AudioConnection patchCord3(playSdWav3, 0, mixer1, 2);
AudioConnection patchCord4(playSdWav4, 0, mixer1, 3);
AudioConnection patchCord5(mixer1, 0, i2s1, 0);
AudioConnection patchCord6(mixer1, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1;
Bounce button0 = Bounce(0, 15);
Bounce button1 = Bounce(1, 15);
Bounce button2 = Bounce(2, 15);
Bounce button3 = Bounce(3, 15); // 15 = 15 ms debounce time
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14
void setup() {
Serial.begin(9600);
AudioMemory(8);
sgtl5000_1.enable();
sgtl5000_1.volume(0.6);
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
if (!(SD.begin(SDCARD_CS_PIN))) {
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
pinMode(13, OUTPUT); // LED on pin 13
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
delay(5); // 10
}
const char *track_A = "SOUND01.WAV"; // some reverb within …
const char *track_B = "SOUND02.WAV";
const char *track_C = "SOUND03.WAV";
const char *track_D = "SOUND04.WAV";
elapsedMillis blinkTime;
void loop() {
// read pushbuttons
button0.update();
if (button0.fallingEdge()) {
Serial.println("Button_0 pushed");
playSdWav1.play(track_A);
}
button1.update();
if (button1.fallingEdge()) {
Serial.println("Button_1 pushed");
playSdWav1.play(track_B);
}
button2.update();
if (button2.fallingEdge()) {
Serial.println("Button_2 pushed");
playSdWav1.play(track_C);
}
button3.update();
if (button3.fallingEdge()) {
Serial.println("Button_3 pushed");
playSdWav1.play(track_D);
}
// blink the LED without delays – not necessary, just to see if Teensy is alive ;-)
if (blinkTime < 250) {
digitalWrite(13, LOW);
} else if (blinkTime < 500) {
digitalWrite(13, HIGH);
} else {
blinkTime = 0; // start blink cycle over again
}
}