ulticontrolled jukebox

hi to everyone,
I hve been reading other posts related to jukebox, but my problem is different, or that is what I think.
The project tries in essence to control mp3trigger(robertsonics) based jukebox with 8 different controllers.
I supposed to have 4 control buttons in each controller:
button1 plays selected song
button2 skip to next song (but do not play it)
button3 skip to previous song (again, not playing the song).
buttton4 take control of the jukebox avoiding other controllers to be listened, until selected song is launched.

I thought that having a button4 for each controller would be the most logic in order to know who masters the control, but i couldn't find the way to know which button4 is pressed before.

I have an Arduino Mega with a mux shield 2 to admin all buttons except the buttons4, a 74hc165 for the buttons4.
As well I have all mp3trigger shield triggers hardwired to the mega in order to send ground to the trigger selected, also I use some pins to display song selected ina 2digits seven segments display.

so my problem is about controlling which button4 is selected first any time there is no song being palyed, and how to give controls to each controller and not the others.

I just avoided making stacks or queues.

Anybody able to help?

so my problem is about controlling which button4 is selected first any time there is no song being palyed, and how to give controls to each controller and not the others.
I just avoided making stacks or queues.

Essentially, you need to learn about “state machines” and how to use variables to control program logic. The Blink Without Delay sketch is a fundamental training program but it is simple compared to 8 controllers with 4 set of identical buttons.

In the case of not using stacks or queues you take away several good options, but perhaps you can get away with using Pin-Change Interrupts for buttons 4. Use an 8 element array, 0 - 7, to represent the buttons and simply set an element in that array. Loop the array as long as the music is playing and keep the interrupts OFF. When the music is finished, clear the array, and then turn on the interrupts again. Use a Select Case, 0 - 7, to control activity for the different controllers - that is, if [5] is non-zero, then the sixty controller is active for the duration of the song.

Ray

Thanks Ray,
I will take a look to each tutorial you mentioned, I thought that I was not doing well.
My programming skills are so noob…
Here is my code:
#code:

int apretado;
int sonar;
int palante;
int patras;
int pista=1;
int jukManda=0;
int skipH;
int skipL;
int triggersOut[]={22,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53};

//variables play-------
int playUno=8;
int playDos=9;
int playTres=10;
int playFour=11;
int playCinc=12;
int playSis=13;
int playSet=14;
int playVuit=15;



void setup(){
//pulsadores turno entrada
pinMode(0, INPUT);
digitalWrite(0, HIGH);
pinMode(1, INPUT);
digitalWrite(1, HIGH);

pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
//PULSADORES TURNO ENTRADA-----
//PULSADORES PLAY SONG-------
pinMode(playUno, INPUT);


pinMode(playDos, INPUT);

pinMode(playTres, INPUT);
pinMode(playFour, INPUT);
pinMode(playCinc, INPUT);
pinMode(playSis, INPUT);
pinMode(playSet, INPUT);
pinMode(playVuit, INPUT);
//pulsadores skipH-------------
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
pinMode(A5, INPUT);
pinMode(A6, INPUT);
pinMode(A7, INPUT);
//pulsadores skipH-----------
//pulsadores skipL-----------
pinMode(A8, INPUT);
pinMode(A9, INPUT);
pinMode(A10, INPUT);
pinMode(A11, INPUT);
pinMode(A12, INPUT);
pinMode(A13, INPUT);
pinMode(A14, INPUT);
pinMode(A15, INPUT);
//pulsadores skipL----------


//TRIGGERS
pinMode(22, OUTPUT);
pinMode(23, OUTPUT);
pinMode(25, OUTPUT);
pinMode(27, OUTPUT);
pinMode(29, OUTPUT);
pinMode(31, OUTPUT);
pinMode(33, OUTPUT);
pinMode(35, OUTPUT);
pinMode(37, OUTPUT);
pinMode(39, OUTPUT);
pinMode(41, OUTPUT);
pinMode(43, OUTPUT);
pinMode(45, OUTPUT);
pinMode(47, OUTPUT);
pinMode(49, OUTPUT);
pinMode(51, OUTPUT);
pinMode(53, OUTPUT);

/*
 pinMode(A, OUTPUT);
 pinMode(B, OUTPUT);
 pinMode(C, OUTPUT);
 pinMode(D, OUTPUT);
 pinMode(E, OUTPUT);
 pinMode(FF, OUTPUT);
 pinMode(G, OUTPUT);

 pinMode(CA1, OUTPUT);
 pinMode(CA2, OUTPUT);*/
}
void loop(){
sonar=0; //inicializo darle al play
apretado=0; // inicializo estado pulsadores turno
jukManda=0; //inicializamos el case por si acaso
pista=0;
digitalWrite(playUno, HIGH);
digitalWrite(playDos, HIGH);
digitalWrite(playTres, HIGH);
digitalWrite(playFour, HIGH);
digitalWrite(playCinc, HIGH);
digitalWrite(playSis, HIGH);
digitalWrite(playSet,HIGH);
digitalWrite(playVuit,HIGH);

digitalWrite(0,HIGH);
digitalWrite(1, HIGH);

do {
  for (int i=0; i<8; i++){//scanear pulsadores de turnos
   apretado= digitalRead(i);
    if (apretado==LOW){
      jukManda=i;
      break;
    }
  }
}while(apretado==HIGH);

switch (jukManda){
  case 1://Jukebox 2 mandos--------------------------------
    do{
      palante= digitalRead(A3);
      if (palante==LOW){
        pista=+1;
      }
      delay(1000);
      patras= digitalRead(A2);
       if (patras==LOW){
        pista=-1;
       }
       delay(1000);
      sonar= digitalRead(playDos);
      delay(1000);    
    }while(sonar==HIGH);
    digitalWrite(triggersOut[pista-1], LOW);
    delay(1000);
    digitalWrite(triggersOut[pista-1], HIGH);
    break;
  case 2: //Jukebox 3 Mandos-------------
    do{
        palante= digitalRead(A5);
        if (palante==LOW){
          pista=+1;
        }
        delay(1000);
        patras= digitalRead(A4);
         if (patras==LOW){
          pista=-1;
         }
         delay(1000);
        sonar= digitalRead(playTres);
        delay(1000);    
      }while(sonar==HIGH);
      digitalWrite(triggersOut[pista-1], LOW);
      delay(1000);
      digitalWrite(triggersOut[pista-1], HIGH);
      break;
  case 3://Jukebox 4 mandos------------------
    do{
        palante= digitalRead(A7);
        if (palante==LOW){
          pista=+1;
        }
        delay(1000);
        patras= digitalRead(A6);
         if (patras==LOW){
          pista=-1;
         }
         delay(1000);
        sonar= digitalRead(playFour);
        delay(1000);    
      }while(sonar==HIGH);
      digitalWrite(triggersOut[pista-1], LOW);
      delay(1000);
      digitalWrite(triggersOut[pista-1], HIGH);
      break;
  case 4://Jukebox 5 mandos------------------
    do{
        palante= digitalRead(A9);
        if (palante==LOW){
          pista=+1;
        }
        delay(1000);
        patras= digitalRead(A8);
         if (patras==LOW){
          pista=-1;
         }
         delay(1000);
        sonar= digitalRead(playCinc);
        delay(1000);    
      }while(sonar==HIGH);
      digitalWrite(triggersOut[pista-1], LOW);
      delay(1000);
      digitalWrite(triggersOut[pista-1], HIGH);
      break;
  case 5://Jukebox 6 mandos------------------
    do{
        palante= digitalRead(A11);
        if (palante==LOW){
          pista=+1;
        }
        delay(1000);
        patras= digitalRead(A10);
         if (patras==LOW){
          pista=-1;
         }
         delay(1000);
        sonar= digitalRead(playSis);
        delay(1000);    
      }while(sonar==HIGH);
      digitalWrite(triggersOut[pista-1], LOW);
      delay(1000);
      digitalWrite(triggersOut[pista-1], HIGH);
      break;
  case 6://Jukebox 7 mandos------------------
    do{
        palante= digitalRead(A13);
        if (palante==LOW){
          pista=+1;
        }
        delay(1000);
        patras= digitalRead(A11);
         if (patras==LOW){
          pista=-1;
         }
         delay(1000);
        sonar= digitalRead(playSet);
        delay(1000);    
      }while(sonar==HIGH);
      digitalWrite(triggersOut[pista-1], LOW);
      delay(1000);
      digitalWrite(triggersOut[pista-1], HIGH);
      break;
  case 7://Jukebox 8 mandos------------------
    do{
        palante= digitalRead(A15);
        if (palante==LOW){
          pista=+1;
        }
        delay(1000);
        patras= digitalRead(A14);
         if (patras==LOW){
          pista=-1;
         }
         delay(1000);
        sonar= digitalRead(playVuit);
        delay(1000);    
      }while(sonar==HIGH);
      digitalWrite(triggersOut[pista-1], LOW);
      delay(1000);
      digitalWrite(triggersOut[pista-1], HIGH);
      break;
  default://Jukebox 1 mandos------------------
    do{
        palante= digitalRead(A1);
        if (palante==LOW){
          pista=+1;
        }
        delay(1000);
        patras= digitalRead(A0);
         if (patras==LOW){
          pista=-1;
         }
         delay(1000);
        sonar= digitalRead(playUno);
        delay(1000);    
      }while(sonar==HIGH);
      digitalWrite(triggersOut[pista-1], LOW);
      delay(1000);
      digitalWrite(triggersOut[pista-1], HIGH);
      break;
      }
}

I am not sure if you will understand var names as palante(skip+), patras(skip-) that are just doing +/-1 to a counter, because, I will have to handle after that a 2digit 7segment display, and I will need everytime the track (pista) number.

In addition, I couldn’t made work fine the 74hc165 shield from sparkfun, It just sends me 11111111 or 00000000, independently of the closed or opened switches (in this case momentary buttons), at the begining that was the way I thought to make know which buttons were pushed first, but I am not sure if the problem is on the serial comunication or what.

I’ve just used to try the example from sparkfun tutorial’s website:
https://learn.sparkfun.com/tutorials/shift-registers/shift-register-example

But you, know, looking at my serial port on arduinio ide, only sequences of 1 or 0, not mixed…