Skip to content

Instantly share code, notes, and snippets.

@amstocker
Created April 8, 2021 21:55
Show Gist options
  • Select an option

  • Save amstocker/2be976c9ae888e557ddf1243b9c73f47 to your computer and use it in GitHub Desktop.

Select an option

Save amstocker/2be976c9ae888e557ddf1243b9c73f47 to your computer and use it in GitHub Desktop.
#include <USBHost_t36.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioPlaySdWav playSdWav1; //xy=272,942
AudioOutputPT8211 pt8211_1; //xy=557,951
AudioConnection patchCord1(playSdWav1, 0, pt8211_1, 0);
AudioConnection patchCord2(playSdWav1, 1, pt8211_1, 1);
// GUItool: end automatically generated code
// USB
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
MIDIDevice midi1(myusb);
const char* wavFile = "1B.WAV";
void play() {
if (!playSdWav1.isPlaying()) {
Serial.println("Playing from SD card...");
if (!playSdWav1.play(wavFile)) {
Serial.println("Could not play from SD card!");
return;
}
delay(5);
while (playSdWav1.isPlaying()) {
Serial.println("Playing...");
delay(100);
}
Serial.println("Done playing.");
}
}
void myNoteOn(byte channel, byte note, byte velocity) {
Serial.print("Note On, ch=");
Serial.print(channel, DEC);
Serial.print(", note=");
Serial.print(note, DEC);
Serial.print(", velocity=");
Serial.println(velocity, DEC);
play();
}
void setup() {
AudioMemory(20);
Serial.begin(115200);
myusb.begin();
midi1.setHandleNoteOn(myNoteOn);
if (!(SD.begin(BUILTIN_SDCARD))) {
Serial.println("Unable to access the SD card");
}
if (SD.exists(wavFile)) {
Serial.println("File exists.");
play();
}
else {
Serial.println("File doesn't exist.");
}
}
void loop() {
myusb.Task();
midi1.read();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment