Hi All,
Sorry that I'm a super mega newbie at programming. I'm trying to make a system using Arduino and VmusicII Mp3 player so that when a switch is closed a long MP3 will play continuously, but when the switch is open VMusic will randomly cycle through a bunch of shorter mp3s.
One issue is that the VMusicII will start over at the beginning of the MP3 everytime it receives a command, but I want it to play continusouly until there is a change in the switch state. A friend suggested that I use code that looks for a change in the switch state to instigate the longer MP3, since it will only send the serial command once per change in this case.
I tried this with and LED and it seems to me that it will do what I want. Now the difficulty that I'm having is that something about the way that I wrote the randomly accessed array for the other MP3s is syntactically annoying to Arduino. I believe that my variables are of a different type and that's what's causing the problem. In any case I receive this error when it gets to this part of the code:
"error: Invalid operands of types 'const char [4]' and 'char*' to binary 'operator+'"
Any suggestions about how to improve the code below would be much appreciated.
//This is code to play one 30 second MP3 repeatedly when the lid of a trashcan is closed
//and then to play a series of randomly accessed 5 second MP3s when the lid is opened.
//Helpers on this code have included Chris Coleman, Sarah Hatton, and Zachary Jones
int switchPin = 3; //pin for open or closed trashcan
int lastSwitch = 0;//variable to keep track of last state of switch
int switch1 = 0;//variable to hold current state of switch
int ledPin = 13;//leds are fun
char* myMP3s[]={"face.mp3", "haircut.mp3", "looks.mp3", "perv.mp3", "recycle.mp3","scrap.mp3"
"smelly.mp3", "stick.mp3", "stupid.mp3", "tree.mp3", "walmart.mp3", "yourmom.mp3"};//an array of mp3s????
int thisMP3 = 0;//a variable to hold one of the mp3s from the array
void setup() {
pinMode(switchPin, INPUT); // declare pushbutton as input
pinMode(ledPin, OUTPUT);//declare led as output
Serial.begin(9600);//let's talk
}
void loop ()
{
thisMP3 = random(0, 11);//a variable that will choose numbers between 0 and 11 to correspond with mp3s
//in the array???this is the part that seems problematic right now like the data types are not corresponding
Serial.println(thisMP3);//lets talk
switch1 = digitalRead(switchPin);//this section makes it so that it only will do the first functions when
//the trashcan lid is open. Chris Coleman suggested this method
if ( switch1 == HIGH && lastSwitch != 1 ) {//if the state of the switch has changed send the serial command
digitalWrite (ledPin, HIGH);
Serial.print("VST");//stop playing this allows more immediate change from one MP3 to the next
Serial.print(13,BYTE);
Serial.print("VPF" + myMP3s[thisMP3]; //this is the hang-up I'm not sure why the intention is that the random
//variable myMP3s is used to select from among the array "thisMP3"
Serial.print(13,BYTE);//a return part of the code that VMusic2 uses
lastSwitch == switch1;
}
else if (switch1 == LOW ); {//as long as the lid is on the trashcan, this code executes
(lastSwitch == 0);}
digitalWrite (ledPin, LOW);
Serial.print("VST");//stop playing
Serial.print(13,BYTE);
Serial.print("VPF happier.mp3"); //play all files
Serial.print(13,BYTE);
}
}