I'm working on a routine for detecting insertion and removal of the T4.1 SD card. It works really well to detect insertion and removal of the card, but once the card is connected and I'm checking to see if it's still connected using (SD.mediaPresent()), it can cause errors reading data back from the card, which in my case leads to horrible square waves coming through my audio playback (spent 2 days to figure that out). Does anyone have a more robust solution?
0
Code:
elapsedMillis checkForSD;
void loop() {
if (checkForSD > 500) {
checkForSD = 0;
if (SD.mediaPresent()) {
if (!root) {
checkForSD = 0;
root = SD.open("/");
if (root) {
if (notify) notify->handleNotify(this, kSD_Card_Inserted);
}
}
}
else {
if (testInstrument) {
instL.disconnect();
instR.disconnect();
testInstrument->stopAudio();
if (notify) notify->handleNotify(this, kUnloadingInstrument);
delete testInstrument;
testInstrument = 0;
}
if (root) {
root.close();
if (notify) notify->handleNotify(this, kSD_Card_Removed);
}
}
}
}
Last edited: