Hi. I have a switch with multiple cases (7)
switch (state_birdbox)
{
case BB_1:
{
if (pressed_button == BIRDBOX1)
{
state_birdbox = BB_2;
setLightsBirdBox(BEC2);
timer = main_time;
}
else
{
if (pressed_button != OUT_OF_BOUNDS)
{
state_birdbox = BB_1;
}
}
break;
}
case BB_2:
{
if (pressed_button == BIRDBOX2)
{
state_birdbox = BB_3;
setLightsBirdBox(BEC3);
timer = main_time;
}
else
{
if (pressed_button != OUT_OF_BOUNDS)
{
state_birdbox = BB_1;
}
}
break;
}
case BB_3:
{
if (pressed_button == BIRDBOX3)
{
state_birdbox = BB_4;
setLightsBirdBox(BEC4);
timer = main_time;
}
else
{
if (pressed_button != OUT_OF_BOUNDS)
{
state_birdbox = BB_1;
}
}
break;
}
case BB_4:
{
if (pressed_button == BIRDBOX4)
{
state_birdbox = BB_5;
setLightsBirdBox(BEC5);
timer = main_time;
}
else
{
if (pressed_button != OUT_OF_BOUNDS)
{
state_birdbox = BB_1;
}
}
break;
}
case BB_5:
{
if (pressed_button == BIRDBOX5)
{
state_birdbox = BB_6;
setLightsBirdBox(BEC6);
timer = main_time;
}
else
{
if (pressed_button != OUT_OF_BOUNDS)
{
state_birdbox = BB_1;
}
}
break;
}
case BB_6:
{
if (pressed_button == BIRDBOX6)
{
state_birdbox = BB_7;
setLightsBirdBox(BEC7);
timer = main_time;
}
else
{
if (pressed_button != OUT_OF_BOUNDS)
{
state_birdbox = BB_1;
}
}
break;
}
case BB_7:
{
if (pressed_button == BIRDBOX7)
{
ret = true;
}
else
{
if (pressed_button != OUT_OF_BOUNDS)
{
state_birdbox = BB_1;
}
}
break;
}
default:
break;
}// end switch
if (main_time - timer > TIME_BETWEEN_BIRDBOX_MS)
{
state_birdbox = BB_1;
}
return ret;
}
All the variables are correctly declared in cpp and .h files. The problem is that when I run this code the board reset its setup phase. Also, wierd is that if I remove any of the cases, the problem dissapears. What can be the cause?
P.S :
(5%) of program storage space, (20%) of dynamic memory,