Program crashes and starts new

Hi,

I have built an interactive Table with LED stripes as display and buttons on every side where you can play minigames. I already have some running games and all the hardware should work. I now want to program the game “paper, scissor, rock” on the table but my problem is, that the program crashes and starts new at a certain point in the game and I dont know why, I hope someone can find the issue in my code.
For this game I am using 4 of the 5 buttons on each side of the table, one each is used for paper, scissor, rock and one for a random choose. Once both sides choose their item, the program continues and displays the chosen item and the winner. So the problem is, once “side1” picks its item, the whole program crashes and starts new (the starting sequence which only is played when you turn on the table comes). The other side (2) can pick its item without any issues.

My code of the picking phase before the program continues:

    byte select1 = 0;
    byte select2 = 0;

    while(!select1 || !select2)
    {
      //get stat of button 1 on side1
      bool button11s = button11.getStat();
      if(button11s && select1 == 0)
      {
        select1 = 1; //select scissor
        //crashes here
        //light up some LEDs for visual effect
        for(int i = 5; i < 8; ++i)
        {
          arrows2to1.clearLEDs(i);
        }
        arrows1to2.lightUp(2, 0, 250, 0);
        arrows1to2.lightUp(3, 0, 250, 0);
      }

      //get stat of button 5 on side1
      bool button15s = button15.getStat();
      if(button15s && select1 == 0)
      {
        select1 = 2; //select stone
        //crashes here
        //light up some LEDs for visual effect 
        for(int i = 5; i < 8; ++i)
        {
          arrows2to1.clearLEDs(i);
        }
        arrows1to2.lightUp(2, 0, 250, 0);
        arrows1to2.lightUp(3, 0, 250, 0);
      }

      //get stat of button 2 on side1
      bool button12s = button12.getStat();
      if(button12s && select1 == 0)
      {
        select1 = 3; //select paper
        //crashes here
        //light up some LEDs for visual effect
        for(int i = 5; i < 8; ++i)
        {
          arrows2to1.clearLEDs(i);
        }
        arrows1to2.lightUp(2, 0, 250, 0);
        arrows1to2.lightUp(3, 0, 250, 0);
      }

      //get stat of button 4 on side1
      bool button14s = button14.getStat();
      if(button14s && select1 == 0)
      {
        select1 = random(1,4); //select random
        //crashes here
        //light up some LEDs for visual effect
        for(int i = 5; i < 8; ++i)
        {
          arrows2to1.clearLEDs(i);
        }
        arrows1to2.lightUp(2, 0, 250, 0);
        arrows1to2.lightUp(3, 0, 250, 0);
      }

      //get stat of button 1 on side2
      bool button21s = button21.getStat();
      if(button21s && select2 == 0)
      {
        select2 = 1; //select paper
        //doesnt crash here
        //light up some LEDs for visual effect
        for(int i = 5; i < 8; ++i)
        {
          arrows1to2.clearLEDs(i);
        }
        arrows2to1.lightUp(2, 0, 250, 0);
        arrows2to1.lightUp(3, 0, 250, 0);
      }

      //get stat of button 5 on side2
      bool button25s = button25.getStat();
      if(button25s && select2 == 0)
      {
        select2 = 2; //select rock
        //doesnt crash here
        //light up some LEDs for visual effect
        for(int i = 5; i < 8; ++i)
        {
          arrows1to2.clearLEDs(i);
        }
        arrows2to1.lightUp(2, 0, 250, 0);
        arrows2to1.lightUp(3, 0, 250, 0);
      }

      //get stat of button 2 on side2
      bool button22s = button22.getStat();
      if(button22s && select2 == 0)
      {
        select2 = 3; //select paper
        //doesnt crash here
        //light up some LEDs for visual effect
        for(int i = 5; i < 8; ++i)
        {
          arrows1to2.clearLEDs(i);
        }
        arrows2to1.lightUp(2, 0, 250, 0);
        arrows2to1.lightUp(3, 0, 250, 0);
      }

      //get stat of button 4 on side2
      bool button24s = button24.getStat();
      if(button24s && select2 == 0)
      {
        select2 = random(1,4); //select random
        //doesnt crash here
        //light up some LEDs for visual effect
        for(int i = 5; i < 8; ++i)
        {
          arrows1to2.clearLEDs(i);
        }
        arrows2to1.lightUp(2, 0, 250, 0);
        arrows2to1.lightUp(3, 0, 250, 0);
      }
    }
    //program will now continue dispaying the chosen items and the winner

So when I put “select1 = 1” in the start, the whole game is working and you can choose the item on the second side and the item on side1 is always scissor. So I’m pretty sure the error occurs inside the picking bracket.
Also the arrows2to1 and arrows1to2 objects with their functions are working in other minigames.
Same with the buttons, they work in other minigames.

Thank you!

Please post a complete sketch as posting a small snippet with no context is usually a waste of time

The Arduino will reset if the input voltage drops. Perhaps some of the lights are drawing more power than the power supply can provide?

Please post a complete sketch as posting a small snippet with no context is usually a waste of time

This is the whole code of the minigame where the program crashes, every other minigame is independent. And I cant post the code of every library I wrote for this, since this would be a lot.
Every object-related code in my snippet is working in the other minigames. I was hoping I made something wrong in the object-unrelated part of the snippet that makes the arduino restart itself.

The Arduino will reset if the input voltage drops. Perhaps some of the lights are drawing more power than the power supply can provide?

All the LEDs have an extern power supply. The strange thing is, that I can select the item on one side but not the other, on both sides the same amount of LEDs are lighting up.

This is the whole code of the minigame where the program crashes

If that is the best that you can do then, sorry, but I am unable to provide any help

If that is the best that you can do then, sorry, but I am unable to provide any help

It was hard for me, desciding which information I need to provide in order to understand the code. I am sorry if the code I posted is confusing, but I don't know what I can do better.
What informations do you need to understand the code?

The whole posted code is inside a function PSR(){} which is called in the main program, when a specific combination of buttons is pressed. After the while()-loop in the function it only displays the chosen item, there is no problem with that code.

oopsy:
What informations do you need to understand the code?

The entire program.

Or, better yet, an MRE. This is a small but complete code that demonstrates the problem at hand (and ONLY that problem) but does not include any unnecessary clutter-code.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.