Question on Interactive Display Case Project


hello all,
i'm not real experienced programming i'm trying work through it.. have working sketch i'm wanting change behavior , can't figure out how it.  it's beyond current skill.

i'm working on display going in childrens museum.  idea simple.  it's interactive display case.  4 items on display.  user opens 1 of 4 doors. each door has it's own switch.  opening door triggers mp3 player play specific mp3 file , switches relay light associated object in display.   the relay stays on until mp3 finished playing , turns off. mp3 can send serial hex command of 0xff when done sketch waits happen , turns off relay. 

i have working ok, possible interrupt playing file when different door opened.  sketch right nothing until file done playing. 



code: [select]

// super hero gadgets

// mp3s - 01 = bat sprays, 02 = utility belt, 03 = bat phone, 04 = robin's vest

int relay1 = 2; // bat sprays
int relay2 = 3; // utility belt
int relay3 = 4; // bat phone
int relay4 = 5; // robin's vest
int button1 = 6;  // bat sprays
int button2 = 7;  // utility belt
int button3 = 8;  // bat phone
int button4 = 9;  // robin's vest
int button1state = 0;
int button2state = 0;
int button3state = 0;
int button4state = 0;




void setup(){
serial.begin(9600);

pinmode(button1, input);
digitalwrite(button1, high);
pinmode(button2, input);
digitalwrite(button2, high);
pinmode(button3, input);
digitalwrite(button3, high);
pinmode(button4, input);
digitalwrite(button4, high);
pinmode(relay1, output);
pinmode(relay2, output);
pinmode(relay3, output);
pinmode(relay4, output);
}

void loop(){
  int button1state = digitalread(button1);
  int button2state = digitalread(button2);
  int button3state = digitalread(button3);
  int button4state = digitalread(button4);
 
  if(button1state == low){
    batsprays();
  }
  if (button2state == low){
    utilitybelt();
  }
  if (button3state == low){
    batphone();
  }
  if (button4state == low){
    robinvest();
  }
    else{
    idle();
  }
   

} // end loop


void idle() { // when game idle.
  serial.println("idle");
  digitalwrite(relay1, low);
  digitalwrite(relay2, low);
  digitalwrite(relay3, low);
  digitalwrite(relay4, low);
}


 
void batsprays(){
 
  serial.println("bat sprays");
  digitalwrite(relay1, high);  // turn on light
  serial.write(0x01);  // play bat spray file
  while (serial.available() >= 0)     // wait music finish playing
  {
    int input = serial.read();        // read input
    if (input == 0xff){   
      break;                          // if file finished break
    }
  }
}


void utilitybelt(){
  serial.println("utility belt");
  digitalwrite(relay2, high);  // turn on light
  serial.write(0x02);  // play utility best file
  while (serial.available() >= 0)     // wait music finish playing
  {
    int input = serial.read();        // read input
    if (input == 0xff) {   
      break;                          // if file finished break
    }
  }
}


void batphone(){
  serial.println("bat phone");
  digitalwrite(relay3, high);  // turn on light
  serial.write(0x03);  // play bat phone file
  while (serial.available() >= 0)     // wait music finish playing
  {
    int input = serial.read();        // read input
    if (input == 0xff) {   
      break;                          // if file finished break
    }
  }
}


void robinvest(){
  serial.println("robin vest");
  digitalwrite(relay4, high);  // turn on light
  serial.write(0x04);  // play robins vest file
  while (serial.available() >= 0)     // wait music finish playing
  {
    int input = serial.read();        // read input
    if (input == 0xff) {   
      break;                          // if file finished break
    }
  }
}



one thought had make possible iterupt playing of 1 file/light opening different door add each of functions:  (add or || each if statement triggers break.

code: [select]

void batsprays(){
 
  serial.println("bat sprays");
  digitalwrite(relay1, high);  // turn on light
  serial.write(0x01);  // play bat spray file
  while (serial.available() >= 0)     // wait music finish playing
  {
    int input = serial.read();        // read input
    if ((input == 0xff) || (button2state == low) || (button3state == low)  || (button4state == low)) {   
      break;                          // if file finished break
    }
  }
}


but when this, relay totally freaks out when button pressed.  switches on , off fast sounds buzzer wrong.  i'm not sure if logic correct.  i'm new 'while' loops.

any appreciated!  hope makes sense. i'd glad elaborate on that's not clear.

thanks

quote
opening door triggers mp3 player play specific mp3 file

what mp3 player using? how connected arduino?

code: [select]
  serial.println("bat sprays");
  digitalwrite(relay1, high);  // turn on light
  serial.write(0x01);  // play bat spray file
  while (serial.available() >= 0)     // wait music finish playing
  {
    int input = serial.read();        // read input

this looks mp3 player connected serial port, , assumes there immediate response device, , response continuous stream of data ends 0xff when track ends.

seems unlikely me either of assumptions correct.

quote
one thought had make possible iterupt playing of 1 file/light opening different door add each of functions:  (add or || each if statement triggers break.

if earlier assumptions correct, values of buttonnstate not change in while loop. so, never trigger break.



Arduino Forum > Using Arduino > Programming Questions > Question on Interactive Display Case Project


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support