OK, I'm new to all this so bear with me.
So I'm just playing around with a random menu system that opens other menu systems, which than have commands, and I'm just using the serial monitor as the display.
and my question is How to I return to my "Main Menu" once I open one of the other menus and test the commands?
for example, my Main Menu has an option is to press 'L', which than opens a 2nd menu screen, and ok I play around with the commands in that menu, now how do I go back to said Main Menu Screen.
I tried using adding a "return" in a case '3': which worked but it didn't re-display the main menu screen in the serial monitor and it also kept my LED2 on, which it's suppose to full reset(off).
Here is the the of what I have so far:
int Var;//Initializes Variable for options within Second Menu Screen POP-UP.
void setup() {
Serial.begin(9600);//For communication to Serial Monitor.
Serial.println("HELLO WELCOME TO THE MAIN MENU SCREEN FOR CHOOSING A MENU SCREEN");
Serial.println(" ");
Serial.println("L - LED Menu");
Serial.println("B - Buzzer Menu");
Serial.println("S - Light Sensor Menu");
Serial.println(" ");
Serial.println("Enter an option.");
}
void loop() {
int Blink = 0;//Initialization for Blink of LED's.
if(Serial.available())//send data only when you receive data:
{
int Menu = Serial.read();//Reads INPUT of MAIN Menu, In our case it's only INPUTS 'L', 'B', Or 'S'.
switch(Menu)//Takes INPUT entered and performs taks according to the "case".
{
case('L')://New Menu Screen POP-UP.
Serial.println(" ");
Serial.println("1 - Blink LEDs Alternately");
Serial.println("2 - Fade LEDs Alternately");
Serial.println(" ");
Serial.println("Enter an option.");
while(1)//Loops
{
if (Serial.available())//send data only when you receive data.
{
Var = Serial.read();//Reads INPUT for 2nd Menu, in our case it's only '1' or '2'.
switch(Var)//Takes INPUT entered and performs taks according to the "case".
{
case '1':
Blink = 1;//Perform tasks based on when Blink is ==1.
break;
case '2':
Blink = 2;//Perform tasks based on when Blink is ==2.
break;
}
}
if (Blink==1)//When Blink is equal to 1 peform the tasks below.
{
for(int LED = 5 ; LED < 7; LED++)//Initalizes Pins 5 and 6 for LEDs
//Alternates between each one continously.
{
pinMode(LED, OUTPUT);//Sets the LED that is currently in line to OUTPUT.
digitalWrite(LED, HIGH);//Sets the 1st LED that is currently in line to HIGH.
delay(150);//150ms delay.
digitalWrite(LED, LOW);//Sets the 2nd LED that is currently in line to LOW.
}
}
if (Blink==2)
{
int LED1 = 5;
int LED2 = 6;
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5)
{
analogWrite(LED1, fadeValue);// sets the value (range from 0 to 255).
analogWrite(LED2, 255 - fadeValue);
delay(30);// wait for 30 milliseconds to see the dimming effect.
}
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5)
// fade out from max to min in increments of 5 points.
{
analogWrite(LED1, fadeValue);// sets the value (range from 0 to 255):
analogWrite(LED2, 255 - fadeValue);
delay(30);// sets the value (range from 0 to 255):
}
}
}
case('B'):
Serial.println(" ");
Serial.println("1 - Sound an SOS Signal Repeatedly");
Serial.println("2 - Make a Continuous Low Tone");
Serial.println("3 - Make a High Pitched Beeping Sound");
Serial.println(" ");
Serial.println("Enter an option.");
break;
case('S'):
Serial.println(" ");
Serial.println("1 - Sound a Tone when it is Dark");
Serial.println("2 - Sound a Tone on Significant Light Changes");
Serial.println(" ");
Serial.println("Enter an option.");
break;
}
}
}