Hi Guy's! I'm a Teensy amature with some Arduino experience.
I'm using the code below to play a sound when a switch is pressed. When te switch is released, the music must stop. This is working great at the moment.
The only problem I encounter is that reading the SD Card only works once - I Keep getting "Unable to access the SD card" untill I disconnect and reconnect my Teensy.
Is this normal behavior? For developing/troubleshooting this is a bit annoying (just clicking the button or reuploading my code doesn't work ).
Also, is there a way to detect if the wav file completed? I Don't want it to start again.
Thank you!
I'm using the code below to play a sound when a switch is pressed. When te switch is released, the music must stop. This is working great at the moment.
The only problem I encounter is that reading the SD Card only works once - I Keep getting "Unable to access the SD card" untill I disconnect and reconnect my Teensy.
Is this normal behavior? For developing/troubleshooting this is a bit annoying (just clicking the button or reuploading my code doesn't work ).
Also, is there a way to detect if the wav file completed? I Don't want it to start again.
Thank you!
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
AudioPlaySdWav playSdWav1;
AudioOutputI2S i2s1;
AudioConnection patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection patchCord2(playSdWav1, 1, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1;
const int haakPin = 24;
// Use these with the Teensy 3.5 & 3.6 SD card
#define SDCARD_CS_PIN BUILTIN_SDCARD
#define SDCARD_MOSI_PIN 11 // not actually used
#define SDCARD_SCK_PIN 13 // not actually used
void setup() {
Serial.begin(9600);
// AUDIO CONFIG
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);
}
}
pinMode(haakPin, INPUT);
delay(100);
}
void loop() {
if (digitalRead(haakPin) == LOW) {
Serial.println("Telefoon opgenomen");
if (playSdWav1.isPlaying() == false) {
playSdWav1.play("test.WAV");
delay(25);
}
} else {
Serial.println("Telefoon ligt op de haak.");
if (playSdWav1.isPlaying() == true) {
playSdWav1.stop();
}
}
delay(500);
}
Last edited: