I'm trying to make a menu for my project where i can navigate between different things and be able to go back in the order i came in.
I get the error variable sized object 'menustack' may not be intialized. It hightlights the for loop inside my function that is being sent an array. What i want it to do is check each value in the array starting from the beginning until it hits a zero where each time its not a zero it will deposit the array{x} into a variable.
Here is my code. (I excluded parts of code in the project that were unrelated to make it easier to read)
int analogValue;
const int buttonPin8 = 8; // the number of the pushbutton pin
const int buttonPin9 = 9; // the number of the pushbutton pin
const int buttonPin10 = 10; // the number of the pushbutton pin
int menustack[6]={0,0,0,0,0,0};
int currentmenuspot=1;
int buttonState = 0; // variable for reading the pushbutton status
void setup()
{
pinMode(buttonPin8, INPUT); //switch on pin 8
pinMode(buttonPin9, INPUT); //switch on pin 8
pinMode(buttonPin10, INPUT); //switch on pin 8
serial.begin(9600);
clearScreen();
}
void loop()
{
findsmenuspot(menustack); //finds current spot by checking array
switch(currentmenuspot) //uses value from array to jump to other menus
{
case 1: mainmenu();
break;
case 2: COsense();
break;
case 3: Temp();
break;
case 4: Text();
break;
}
if(digitalRead(buttonPin8)==LOW)
{
//do something
}
else if(digitalRead(buttonPin9)==LOW)
{
//do something
}
else if(digitalRead(buttonPin10)==LOW)
{
//do something
}
}
int findsmenuspot(int menustack[])
{
for(int c=0, menustack
=!0, c++ ) //here is the line that the error is hightlingting
{
currentmenuspot=menustack[c];
}
}
[serial_lcd_CO_sensor_multi_menu.ino|attachment](upload://psxGVohjVT0la3soVjSWoyHgYV1.ino) (2.22 KB)