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!