Update 'Feather-M4-Express_NeoTrellis_Music-Maker-FeatherWing-w-Amp.ino'

This commit is contained in:
Danny Bessems 2019-08-11 20:54:18 +00:00
parent f63e983a72
commit 880b621c14
1 changed files with 59 additions and 27 deletions

View File

@ -5,9 +5,9 @@
#include <SD.h> #include <SD.h>
#include <Adafruit_VS1053.h> #include <Adafruit_VS1053.h>
// Set up NeoTrellis // Declare NeoTrellis constants
Adafruit_NeoTrellis trellis; Adafruit_NeoTrellis trellis;
#define INT_PIN 11 // Interrupt pin needs to be unused by MusicMaker #define NT_INTERRUPT 11 // Interrupt pin needs to be unused by MusicMaker
#define MAX_RIPPLES 16 #define MAX_RIPPLES 16
#define FALLOFF_TIME 30 #define FALLOFF_TIME 30
@ -16,12 +16,48 @@ Adafruit_NeoTrellis trellis;
#define RIPPLE_RATE .4 #define RIPPLE_RATE .4
#define MATRIX_POINT(x,y) ((y)*4+(x)) #define MATRIX_POINT(x,y) ((y)*4+(x))
// Set up MusicMaker // Declare MusicMaker constants
#define VS1053_RESET -1 // VS1053 reset pin (not used!) #define MM_RESET -1 // VS1053 reset pin (not used!)
#define VS1053_CS 6 // VS1053 chip select pin (output) #define MM_CS 6 // VS1053 chip select pin (output)
#define VS1053_DCS 10 // VS1053 Data/command select pin (output) #define MM_DCS 10 // VS1053 Data/command select pin (output)
#define CARDCS 5 // Card chip select pin #define MM_DREQ 9 // VS1053 Data request, ideally an Interrupt pin
#define VS1053_DREQ 9 // VS1053 Data request, ideally an Interrupt pin #define SD_CARDCS 5 // Card chip select pin
// Declare Sketch-specific global variables
const char *ClipNames[4][12] = {
{
"DOIT.mp3",
"MAKEIT.mp3",
"WORKIT.mp3",
"",
"HARDER.mp3",
"BETTER.mp3",
"FASTER.mp3",
"STRONGER.mp3",
},
{
"CRICK.mp3",
"FAIL.mp3",
"BITEASS.mp3",
"MARIO.mp3",
"PADUM.mp3",
"PHONE.mp3",
"WINNER.mp3",
"WRONG.mp3"
},
{
"WRONG.mp3"
},
{
"WRONG.mp3"
}
};
const char *TrackNames[4][12] = {
{
"AA000001.mp3",
"AA000002.mp3"
}
};
uint32_t colors[] = { uint32_t colors[] = {
0xFF0000, 0x00FF00, 0x0000FF, 0xFF0000, 0x00FF00, 0x0000FF,
@ -73,44 +109,40 @@ TrellisCallback blink(keyEvent evt){
return 0; return 0;
} }
// Create new instance of VS1053_FilePlayer
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer musicPlayer =
Adafruit_VS1053_FilePlayer(VS1053_RESET, VS1053_CS, VS1053_DCS, VS1053_DREQ, CARDCS); Adafruit_VS1053_FilePlayer(MM_RESET, MM_CS, MM_DCS, MM_DREQ, SD_CARDCS);
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
// Wait for serial port to be opened, remove this line for 'standalone' operation // Wait for serial port to be opened, remove this line for 'standalone' operation
while (!Serial) { delay(1); } while (!Serial) { delay(1); }
delay(500); /* delay(500);
Serial.println("\n\nAdafruit VS1053 Feather Test"); */
if (! musicPlayer.begin()) { // initialise the music player if (! musicPlayer.begin()) { // initialise the music player
Serial.println(F("Couldn't find VS1053, do you have the right pins defined?")); Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
while (1); while (1);
} }
Serial.println(F("VS1053 found")); /*
// Leaving this here for reference purposes
musicPlayer.sineTest(0x44, 500); // Make a tone to indicate VS1053 is working musicPlayer.sineTest(0x44, 500);
*/
if (!SD.begin(CARDCS)) { if (!SD.begin(SD_CARDCS)) {
Serial.println(F("SD failed, or not present")); Serial.println(F("SD failed, or not present"));
while (1); // don't do anything more while (1); // don't do anything more
} }
Serial.println("SD OK!");
// Set volume for left, right channels. lower numbers == louder volume! // Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(25,25); musicPlayer.setVolume(25,25);
musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int
// Play a file in the background, REQUIRES interrupts! // Play a file in the background, REQUIRES interrupts!
/* Serial.println(F("Playing full track 001")); musicPlayer.startPlayingFile("/TRACKS/AA000002.mp3");
musicPlayer.playFullFile("/track001.mp3");
*/
Serial.println(F("Playing track 002"));
musicPlayer.startPlayingFile("/track002.mp3");
pinMode(INT_PIN, INPUT); pinMode(NT_INTERRUPT, INPUT);
randomSeed(analogRead(0)); randomSeed(analogRead(0));
if(!trellis.begin()){ if(!trellis.begin()){
@ -146,13 +178,13 @@ void setup() {
void loop() { void loop() {
Serial.print("."); Serial.print(".");
// File is playing in the background // File is playing in the background
if (musicPlayer.stopped()) { /* if (musicPlayer.stopped()) {
Serial.println("Done playing music"); Serial.println("Done playing music");
while (1) { while (1) {
delay(10); // we're done! do nothing... delay(10); // we're done! do nothing...
} }
} }
if (Serial.available()) { */ if (Serial.available()) {
char c = Serial.read(); char c = Serial.read();
// if we get an 's' on the serial console, stop! // if we get an 's' on the serial console, stop!
@ -172,7 +204,7 @@ void loop() {
} }
} }
if(!digitalRead(INT_PIN)){ if(!digitalRead(NT_INTERRUPT)){
trellis.read(false); trellis.read(false);
} }
processRipples(); processRipples();