Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Adafruit_VS1053.h>
- #include <SD.h>
- //#include <Servo.h>
- //Servo myservo;
- #define SHIELD_RESET -1
- #define SHIELD_CS 7
- #define SHIELD_DCS 6
- #define CARDCS 4
- #define DREQ 3
- Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
- int staticOn = 1;
- int pos = 0;
- const int buttonPin = 2;
- const int lucidcode1 = 7; //23
- const int lucidcode2 = 12; //D1
- const int lucidcode3 = 6; //Green
- const int infilcode1 = 14; //35
- const int infilcode2 = 8; //B6
- const int infilcode3 = 0; //Red
- const int infilcode4 = 42; //80
- const int infilcode5 = 17; //A33
- const int infilcode6 = 10;//Purple
- int buttonState = 0;
- boolean lucidwin = false;
- boolean infilwin = false;
- unsigned long startTime = 0;
- unsigned long onTime = 1000;
- int relay = 1;
- int whiteled = 8;
- int bluePin = 9;
- int greenPin = 10;
- int redPin = 5;
- int outputValue1 = 0;
- int sensorValue1 = 0;
- int outputValue2 = 0;
- int sensorValue2 = 0;
- int outputValue3 = 0;
- int sensorValue3 = 0;
- int flipmode = 0;
- int infilcount = 0;
- void setup() {
- //Serial.begin(9600);
- Serial.println("Adafruit VS1053 Library 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"));
- if (!SD.begin(CARDCS)) {
- Serial.println(F("SD failed, or not present"));
- //while (1); // don't do anything more
- }
- Serial.println("SD OK!");
- printDirectory(SD.open("/"), 0);
- // Set volume for left, right channels. lower numbers == louder volume!
- musicPlayer.setVolume(35,35);
- if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT))
- Serial.println(F("DREQ pin is not an interrupt pin"));
- //musicPlayer.sineTest(0x44, 100); // Make a tone to indicate VS1053 is working
- // myservo.attach(8);
- pinMode(whiteled, OUTPUT);
- pinMode(redPin, OUTPUT);
- pinMode(greenPin, OUTPUT);
- pinMode(bluePin, OUTPUT);
- pinMode(buttonPin, INPUT);
- pinMode(relay, OUTPUT);
- digitalWrite(relay, LOW);
- }
- void setColor(int red, int green, int blue)
- {
- #ifdef COMMON_ANODE
- red = 255 - red;
- green = 255 - green;
- blue = 255 - blue;
- #endif
- analogWrite(redPin, red);
- analogWrite(greenPin, green);
- analogWrite(bluePin, blue);
- }
- void printDirectory(File dir, int numTabs) {
- while(true) {
- File entry = dir.openNextFile();
- if (! entry) {
- // no more files
- //Serial.println("**nomorefiles**");
- break;
- }
- for (uint8_t i=0; i<numTabs; i++) {
- Serial.print('\t');
- }
- Serial.print(entry.name());
- if (entry.isDirectory()) {
- Serial.println("/");
- printDirectory(entry, numTabs+1);
- } else {
- // files have sizes, directories do not
- Serial.print("\t\t");
- Serial.println(entry.size(), DEC);
- }
- entry.close();
- }
- }
- void NoWinners(){
- lucidwin = false;
- infilwin = false;
- }
- void LucidWinner(){
- delay(400);
- Serial.println("DREAM TRANSMISSION ACTIVATED");
- musicPlayer.stopPlaying();
- Serial.println("Playing lswin.mp3");
- musicPlayer.startPlayingFile("lswin.mp3");
- digitalWrite(relay, HIGH);
- setColor(0, 0, 0);
- delay(200);
- setColor(0, 0, 255);
- delay(200);
- setColor(0, 0, 0);
- delay(200);
- setColor(0, 0, 255);
- delay(200);
- setColor(0, 0, 0);
- delay(200);
- setColor(0, 0, 255);
- delay(200);
- setColor(0, 0, 0);
- delay(200);
- setColor(0, 0, 255);
- delay(200);
- setColor(0, 0, 0);
- delay(200);
- setColor(0, 0, 255);
- delay(200);
- setColor(0, 0, 0);
- delay(200);
- setColor(0, 0, 255);
- delay(40000);
- musicPlayer.stopPlaying();
- Serial.println("lssong.mp3");
- musicPlayer.startPlayingFile("lssong.mp3");
- delay (177000);
- //for (pos = 0; pos <= 180; pos += 1) {
- // myservo.write(pos);
- // delay(25);
- //}
- }
- void LucidCode1Entered(){
- delay(1000);
- setColor(0, 0, 255);
- musicPlayer.stopPlaying();
- Serial.println("send.mp3");
- musicPlayer.startPlayingFile("send.mp3");
- //musicPlayer.sineTest(0x44, 50);
- Serial.println("LUCID 1 CODE HAS BEEN ENTERED");
- delay(1000);
- setColor(0, 0, 0);
- musicPlayer.stopPlaying();
- delay(800);
- }
- void LucidCode2Entered(){
- delay(1000);
- setColor(0, 0, 255);
- musicPlayer.stopPlaying();
- Serial.println("Playing send.mp3");
- musicPlayer.startPlayingFile("send.mp3");
- //musicPlayer.sineTest(0x22, 50);
- Serial.println("LUCID 2 CODE HAS BEEN ENTERED");
- delay(1000);
- setColor(0, 0, 0);
- musicPlayer.stopPlaying();
- delay(800);
- }
- void LucidCode3Entered(){
- delay(1000);
- setColor(0, 0, 255);
- musicPlayer.stopPlaying();
- Serial.println("Playing send.mp3");
- musicPlayer.startPlayingFile("send.mp3");
- //musicPlayer.sineTest(0x10, 50);
- Serial.println("LUCID 3 CODE HAS BEEN ENTERED");
- delay(1000);
- setColor(0, 0, 0);
- musicPlayer.stopPlaying();
- delay(800);
- }
- void InfilWin(){
- delay(400);
- setColor(0, 0, 0);
- delay(200);
- setColor(255, 0, 0);
- delay(200);
- setColor(0, 0, 0);
- delay(200);
- setColor(255, 0, 0);
- delay(200);
- setColor(0, 0, 0);
- delay(200);
- setColor(255, 0, 0);
- delay(200);
- setColor(0, 0, 0);
- delay(200);
- setColor(255, 0, 0);
- delay(200);
- setColor(0, 0, 0);
- delay(200);
- setColor(255, 0, 0);
- delay(200);
- setColor(0, 0, 0);
- delay(200);
- setColor(255, 0, 0);
- Serial.println("TRANSMISSION DEVICE DEACTIVATED!");
- musicPlayer.stopPlaying();
- Serial.println("Playing infwin.mp3");
- musicPlayer.startPlayingFile("infwin.mp3");
- delay(39000);
- Serial.println("Playing insong.mp3");
- musicPlayer.startPlayingFile("insong.mp3");
- delay (73500);
- setColor(0, 0, 0);
- }
- void InfilCode1Entered(){
- delay(1000);
- setColor(255, 0, 0);
- musicPlayer.stopPlaying();
- Serial.println("Playing send.mp3");
- musicPlayer.startPlayingFile("send.mp3");
- Serial.println("DESTRUCTION CODE 1 HAS BEEN ENTERED");
- delay(1000);
- setColor(0, 0, 0);
- musicPlayer.stopPlaying();
- delay(800);
- }
- void InfilCode2Entered(){
- delay(1000);
- setColor(255, 0, 0);
- musicPlayer.stopPlaying();
- Serial.println("Playing send.mp3");
- musicPlayer.startPlayingFile("send.mp3");
- Serial.println("DESTRUCTION CODE 2 HAS BEEN ENTERED");
- delay(1000);
- setColor(0, 0, 0);
- musicPlayer.stopPlaying();
- delay(800);
- }
- void InfilCode3Entered(){
- delay(1000);
- setColor(255, 0, 0);
- musicPlayer.stopPlaying();
- Serial.println("Playing send_switch.mp3");
- musicPlayer.startPlayingFile("send.mp3");
- Serial.println("DESTRUCTION CODE 3 HAS BEEN ENTERED");
- delay(1000);
- setColor(0, 0, 0);
- musicPlayer.stopPlaying();
- delay(800);
- }
- void InfilCode4Entered(){
- delay(1000);
- setColor(255, 0, 0);
- musicPlayer.stopPlaying();
- Serial.println("Playing send_switch.mp3");
- musicPlayer.startPlayingFile("send.mp3");
- Serial.println("DESTRUCTION CODE 4 HAS BEEN ENTERED");
- delay(1000);
- setColor(0, 0, 0);
- musicPlayer.stopPlaying();
- delay(800);
- }
- void InfilCode5Entered(){
- delay(1000);
- setColor(255, 0, 0);
- musicPlayer.stopPlaying();
- Serial.println("Playing send.mp3");
- musicPlayer.startPlayingFile("send.mp3");
- Serial.println("DESTRUCTION CODE 5 HAS BEEN ENTERED");
- delay(1000);
- setColor(0, 0, 0);
- musicPlayer.stopPlaying();
- delay(800);
- }
- void InfilCode6Entered(){
- delay(1000);
- setColor(255, 0, 0);
- musicPlayer.stopPlaying();
- Serial.println("Playing send.mp3");
- musicPlayer.startPlayingFile("send.mp3");
- Serial.println("DESTRUCTION CODE 6 HAS BEEN ENTERED");
- delay(1000);
- setColor(0, 0, 0);
- musicPlayer.stopPlaying();
- delay(800);
- }
- void loop() {
- if (staticOn == 1) {
- Serial.println("Playing static_1.mp3");
- musicPlayer.startPlayingFile("static_1.mp3");
- staticOn = 0; //flip the flag so it doesn't start playing over again
- }
- while (musicPlayer.playingMusic) {
- // file is now playing in the 'background'
- //setColor(255, 255, 0); // yellow
- digitalWrite(whiteled, HIGH);
- int buttonState = digitalRead(buttonPin);
- sensorValue1 = analogRead(A0);
- outputValue1 = map(sensorValue1, 0, 1023, 0, 45);
- sensorValue2 = analogRead(A1);
- outputValue2 = map(sensorValue2, 0, 1023, 30, 0);
- sensorValue3 = analogRead(A3);
- outputValue3 = map(sensorValue3, 0, 1023, 10, 0);
- if (buttonState == 1 && flipmode == 0) {
- setColor(0, 0, 0); // yellow
- //Serial.println("No Winners");
- }
- if (buttonState == 0) {
- setColor(255, 255, 0); // yellow
- }
- if (outputValue1 != infilcode1 && outputValue2 != infilcode2 && outputValue3 != infilcode3 && outputValue1 != lucidcode1 && outputValue2 != lucidcode2 && outputValue3 != lucidcode3 && buttonState == HIGH) {
- NoWinners();
- }
- if (outputValue1 == lucidcode1 && outputValue2 == lucidcode2 && outputValue3 == lucidcode3 && buttonState == HIGH && flipmode == 0) {
- lucidwin = true;
- startTime = millis();
- }
- else {
- NoWinners();
- }
- if (lucidwin && millis() - startTime < onTime) {
- LucidWinner();
- //while(1);
- }
- if (outputValue1 == lucidcode1 && buttonState == HIGH && flipmode == 0) {
- LucidCode1Entered();
- }
- if (outputValue2 == lucidcode2 && buttonState == HIGH && flipmode == 0) {
- LucidCode2Entered();
- }
- if (outputValue3 == lucidcode3 && buttonState == HIGH && flipmode == 0) {
- LucidCode3Entered();
- }
- if (outputValue1 == infilcode1){
- infilcount++;
- }
- if (outputValue2 == infilcode2){
- infilcount++;
- }
- if (outputValue3 == infilcode3){
- infilcount++;
- }
- if (outputValue1 == infilcode4){
- infilcount++;
- }
- if (outputValue2 == infilcode5){
- infilcount++;
- }
- if (outputValue3 == infilcode6){
- infilcount++;
- }
- Serial.println(infilcount);
- if (infilcount >= 3 && buttonState == HIGH && flipmode == 0) {
- infilwin = true;
- startTime = millis();
- }
- else {
- NoWinners();
- }
- if (infilwin && millis() - startTime < onTime) {
- InfilWin();
- while(1);
- }
- if (outputValue1 == infilcode1 && buttonState == HIGH && flipmode == 0) {
- InfilCode1Entered();
- }
- if (outputValue2 == infilcode2 && buttonState == HIGH && flipmode == 0) {
- InfilCode2Entered();
- }
- if (outputValue3 == infilcode3 && buttonState == HIGH && flipmode == 0) {
- InfilCode3Entered();
- }
- if (outputValue1 == infilcode4 && buttonState == HIGH && flipmode == 0) {
- InfilCode4Entered();
- }
- if (outputValue2 == infilcode5 && buttonState == HIGH && flipmode == 0) {
- InfilCode5Entered();
- }
- if (outputValue3 == infilcode6 && buttonState == HIGH && flipmode == 0) {
- InfilCode6Entered();
- }
- Serial.print(outputValue1);
- Serial.print(", ");
- Serial.print(outputValue2);
- Serial.print(", ");
- Serial.print(outputValue3);
- Serial.print(", ");
- Serial.println(buttonState);
- delay(120);
- infilcount = 0;
- if (buttonState == HIGH) {
- flipmode=1;
- }
- if (buttonState == LOW) {
- flipmode=0;
- }
- if(musicPlayer.stopped()) {
- Serial.println("End of file.\n");
- staticOn=1; //reset counter so static will start again
- }
- }
- }
Add Comment
Please, Sign In to add comment