mikrofalowka
Member
Hi,
I want to build an interface that is going to trigger 1 of 10 sound sample. I tried to do it with the playMem option but memory is too low to keep that many samples. I am trying to do it via SD card but I cant make it work. I am using Teensy 3.2 with audio board. Everything is soldered correctly (did the hardware check) and the SD card is good as well (SanDisk ultra 16gb class 1). I was trying to do it with the codes from tutorial as I am only a beginner programmer. Any ideas? Please I need help because its for a project of friend of mine and I thought I could manage it. Thanks in advance!
I want to build an interface that is going to trigger 1 of 10 sound sample. I tried to do it with the playMem option but memory is too low to keep that many samples. I am trying to do it via SD card but I cant make it work. I am using Teensy 3.2 with audio board. Everything is soldered correctly (did the hardware check) and the SD card is good as well (SanDisk ultra 16gb class 1). I was trying to do it with the codes from tutorial as I am only a beginner programmer. Any ideas? Please I need help because its for a project of friend of mine and I thought I could manage it. Thanks in advance!
Code:
#include <Bounce.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioPlaySdWav playSdWav3; //xy=101.00000762939453,217.0000057220459
AudioPlaySdWav playSdWav2; //xy=147.00000762939453,138.00000381469727
AudioPlaySdWav playSdWav1; //xy=162.00000762939453,91.00000381469727
AudioMixer4 mixer1; //xy=335,143
AudioOutputI2S i2s1; //xy=555.0000381469727,138.00001525878906
AudioConnection patchCord1(playSdWav3, 0, mixer1, 2);
AudioConnection patchCord2(playSdWav2, 0, mixer1, 1);
AudioConnection patchCord3(playSdWav1, 0, mixer1, 0);
AudioConnection patchCord4(mixer1, 0, i2s1, 0);
AudioConnection patchCord5(mixer1, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=394.00000762939453,228.00003051757812
// GUItool: end automatically generated code
// Bounce objects to read pushbuttons
Bounce button0 = Bounce(0, 15);
Bounce button1 = Bounce(1, 15); // 15 ms debounce time
Bounce button2 = Bounce(2, 15);
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14
void setup() {
Serial.begin(9600);
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
AudioMemory(8);
sgtl5000_1.enable();
sgtl5000_1.volume(0.5);
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);
}
}
}
void playFile(const char *filename)
{
Serial.print("Playing file: ");
Serial.println(filename);
playSdWav1.play(filename);
delay(100);
while (playSdWav1.isPlaying()) {
}
}
void loop() {
button0.update();
button1.update();
button2.update();
if (button0.fallingEdge()) {
playFile("JOANNA1"); // filenames are always uppercase 8.3 format
}
delay(5000);
if (button1.fallingEdge()) {
playFile("JOANNA2");
}
delay(5000);
if (button2.fallingEdge()) {
playFile("JOANNA3");
}
delay(5000);
/*if (button3.fallingEdge()) {
playFile("JOANNA4");
delay(1500);
}*/
}