Need help with a program. Please look at and give suggestions.

Hi,
I need help with a graduation progect wich needs to be done on the 11 of May (yes it is May :sweat_smile:). It is supposed to play a mp3 file (don’t worry about the code that plays this) when a switch turns on until the switch turns off where another file will be played. The button is going to be on when a door open and when they close the door, it will shut off. I made my first version but it didn’t work. If someone could figure out what I am doing wrong and fix it or give me sugestions, i’d be very thankful.
My first version is this:

int smdswitchPin = 2;
int ampPin = 3;
int bgdswitchPin = 4;
int lightPin = 5;
int ledPin = 6;
boolean ledOn = false;
boolean ledOff =true;

unsigned char cmd_buf[10];
unsigned char i;

void ArduinoMP3Shield_SendCMD(unsigned char *cmd_buf, unsigned len)
{
    unsigned i;
    for(i=0; i<len; i++){
        Serial.write(cmd_buf[i]);
    }
}

void setup()
{
  pinMode(smdswitchPin, INPUT);
  pinMode(ampPin, OUTPUT);
  pinMode(bgdswitchPin, INPUT);
  pinMode(lightPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  
   /**code to set volume*/
   }

void loop()
{
  if (digitalRead(bgdswitchPin) == HIGH)
  {
    if (ledOn == ledOff)
    {
      digitalWrite(lightPin, HIGH);
      
      /**code to play first file*/
      
      ledOn != ledOn;
    }
    else
    {
    }
  }
  else
  {
    if (ledOn != ledOff)
    {
      /**code to play second file*/
      
      ledOn != ledOn;
    }
  }
}

as you can see, i’ve taken out the code for setting the player and playing the files(i can put that in) so it would not be so long.

I also have a problem with sending the serial code to the device playing the music because when i run the program the serial sends it over and over again and again. does anyone have any suggestions on correcting this?

Thanks

This statement does nothing:

ledOn != ledOn;

The != is only a comparison operator, it does not negate and assign the value.

You can use this:

ledOn = ~ledOn;

Pete

Thanks, I wondered if what I had would work! XD