I have a basic MP3 player using the prop shield LC from Frank B's MP3 player here
The code below basically will play the MP3 file based off a pin trigger. With so many inputs (eventually possibly hooking up a matrix) I am wondering what the best way to save power moving forward... Ideally a trigger button can be pressed and wake up the teensy and jump right to the MP3 file being played. Any help is greatly appreciated!
The code below basically will play the MP3 file based off a pin trigger. With so many inputs (eventually possibly hooking up a matrix) I am wondering what the best way to save power moving forward... Ideally a trigger button can be pressed and wake up the teensy and jump right to the MP3 file being played. Any help is greatly appreciated!
Code:
// Simple MP3 file player example
// https://forum.pjrc.com/threads/27059-MP3-Player-Lib-with-example?p=101537&viewfull=1#post101537
// Requires the prop-shield and Teensy 3.2 or 3.1
// This example code is in the public domain.
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <play_sd_mp3.h> // https://github.com/FrankBoesing/Arduino-Teensy-Codec-lib
//#include <play_sd_aac.h>
#include <Bounce2.h>
// GUItool: begin automatically generated code
//AudioPlaySdWav playSdWav1; //xy=154,422
AudioPlaySdMp3 playMp31; //xy=154,422
AudioMixer4 mixer1; //xy=327,432
AudioOutputAnalog dac1; //xy=502,412
AudioConnection patchCord1(playMp31, 0, mixer1, 0);
AudioConnection patchCord2(playMp31, 1, mixer1, 1);
AudioConnection patchCord3(mixer1, dac1);
// GUItool: end automatically generated code
#define PROP_AMP_ENABLE 5
#define FLASH_CHIP_SELECT 6
//#define FLASH_CHIP_SELECT 21 // Arduino 101 built-in SPI Flash
// Bounce objects to read two pushbuttons (pins 0,1)
Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5); // 5 ms debounce time
void setup() {
// Configure the pushbutton pins for pullups. Each button should connect from the pin to GND.
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
Serial.begin(9600);
AudioMemory(8); //4
delay(2000);
// Start SerialFlash
if (!SerialFlash.begin(FLASH_CHIP_SELECT)) {
while (1) {
Serial.println ("Cannot access SPI Flash chip");
delay (1000);
}
}
//Set Volume
mixer1.gain(0, 0.9);
mixer1.gain(1, 0.9);
//Start Amplifier
pinMode(PROP_AMP_ENABLE, OUTPUT);
digitalWrite(PROP_AMP_ENABLE, HIGH); // Enable Amplifier
}
void playFile(const char *filename)
{
SerialFlashFile ff = SerialFlash.open(filename);
Serial.print("Playing file: ");
Serial.println(filename);
uint32_t sz = ff.size();
uint32_t pos = ff.getFlashAddress();
// Start playing the file. This sketch continues to
// run while the file plays.
playMp31.play(pos,sz);
// Simply wait for the file to finish playing.
/*
while (playMp31.isPlaying()) {
yield();
}
*/
}
void loop() {
//
// Update all the button objects
button0.update();
button1.update();
//
if (button0.fell()) {
// playMp31.stop();
playFile("PinZero.mp3");
} else if (button1.fell()) {
// playMp31.stop();
playFile("PinOne.mp3");
}
//
}