Created
February 13, 2020 23:36
-
-
Save brysonian/bc0091cedc7f1da32e9836d49c0a5b04 to your computer and use it in GitHub Desktop.
Demo of using Music Maker FeatherWing on Feather32u4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int POT_PIN = A0; | |
// include SPI, MP3 and SD libraries | |
#include <SPI.h> | |
#include <SD.h> | |
#include <Adafruit_VS1053.h> | |
#define Reset -1 | |
//These are pins used | |
#define CS 6//chip select | |
#define DCS 10//Data select | |
#define Card 5//card select pin | |
#define DQ 9//Data request | |
//makes a new object named music player | |
Adafruit_VS1053_FilePlayer musicPlayer = | |
Adafruit_VS1053_FilePlayer(Reset, CS, DCS, DQ, Card); | |
void setup() { | |
// wait for music player | |
if (! musicPlayer.begin()) { | |
while (1); | |
} | |
// wait for SD card | |
if (!SD.begin(Card)) { | |
while (1); | |
} | |
musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); | |
} | |
void loop() { | |
int val = analogRead(POT_PIN); | |
if (val < 500 && !musicPlayer.playingMusic) { | |
if (! musicPlayer.startPlayingFile("/001.mp3")) { | |
while (1); | |
} | |
} else if (musicPlayer.playingMusic) { | |
musicPlayer.setVolume(val / 4, val / 4); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment