Created
March 21, 2016 01:56
-
-
Save yakticus/548c2698d3e20321812f to your computer and use it in GitHub Desktop.
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
| // include SPI, MP3 and SD libraries | |
| #include <SPI.h> | |
| #include <Adafruit_VS1053.h> | |
| #include <SD.h> | |
| // These are the pins used for the music maker shield | |
| #define SHIELD_RESET -1 // VS1053 reset pin (unused!) | |
| #define SHIELD_CS 7 // VS1053 chip select pin (output) | |
| #define SHIELD_DCS 6 // VS1053 Data/command select pin (output) | |
| int photoresistor = 15; // This is where your photoresistor is plugged in. The other side goes to the "power" pin (below). | |
| const int darkValue = 25; | |
| const int lightValue = 75; | |
| bool open = false; | |
| // These are common pins between breakout and shield | |
| #define CARDCS 4 // Card chip select pin | |
| // DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt | |
| #define DREQ 3 // VS1053 Data request, ideally an Interrupt pin | |
| Adafruit_VS1053_FilePlayer musicPlayer = | |
| Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS); | |
| void setup() { | |
| Serial.begin(9600); | |
| Serial.println("Adafruit VS1053 Simple Test"); | |
| if (!musicPlayer.begin()) { // initialise the music player | |
| Serial.println(F("Couldn't find VS1053, do you have the right pins defined?")); | |
| while (1); | |
| } | |
| Serial.println(F("VS1053 found")); | |
| SD.begin(CARDCS); // initialise the SD card | |
| // Set volume for left, right channels. lower numbers == louder volume! | |
| musicPlayer.setVolume(5,5); | |
| // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background | |
| // audio playing | |
| musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int | |
| } | |
| // keeps state of which file to play next | |
| int fileNum = 0; | |
| char* filenames[] = {"track001.mp3", "track002.mp3", "track003.mp3", "track004.mp3", "track005.mp3", "track006.mp3", "track007.mp3", "track000.mp3"}; | |
| void loop() { | |
| int analogValue = analogRead(photoresistor); | |
| if (analogValue <= darkValue) { | |
| open = false; | |
| } else if (analogValue >= lightValue) { | |
| if (!open) { | |
| open = true; | |
| musicPlayer.playFullFile(filenames[fileNum % 8]); | |
| fileNum++; | |
| delay(2000); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment