using a boolean inside the brackets of a void function

Hi All Happy New Year.
I have a question:

void Screen2(boolean = false)
{
  lcd.setCursor(0, 0);
  lcd.print("Clock Set      U");
  lcd.setCursor(14, 0);
  lcd.write((uint8_t)0);
  lcd.setCursor(0, 1);
  lcd.print("Timer Set      D");
  lcd.setCursor(14, 1);
  lcd.write((uint8_t)0);
}

I have this function which is for a screen layout on and LCD. Now within the Loop Function I would like to say something like this:

void loop()
{
  ButtonPush = ReadButtons();
  
  if (ReadButtons() == BtnE)
  {
    BtnRelease();
    Screen2();
  }
  if (Screen2(true))
  {
    do smoething here
  }

Will this work?

Void means returns nothing so it make no sense to use it in that way.

Mark

void Screen2(boolean = false)

I'm not sure if C++ allows it (C# would) if you get the syntax right.

But below will definitely not work as Screen2 does not return anything

if (Screen2(true))

Maybe explain what you want to achieve and you might get an answer

What I want to happen is this;

Void Screen2 is a LCD menu which has 2 lines
1/ Timers SetUp
2/ Clock SetUp

In my first part of the loop I have called Screen2 by means of pushing button BtnE. The second part of my sketch will be "if you are presently in Screen2 (ie my initial idea of using a Boolean) I need to either press button x to go to Timers or button y to go to Clock.

You could have it use a global to record what screen it is showing at the moment

You can't assign a value to a datatype.

You could have it use a global to record what screen it is showing at the moment

What do you mean?

Did you mean something like

void Screen2(boolean b = false)

Proietti:
What do you mean?

void Screen2(boolean = false)

boolean is a data type. You assign values to variables of some type.

Since you don't have a variable, you can, obviously, never reference the variable in the function, so it doesn't make sense to even have the argument with a default value.

So, instead you can try to use an enum...

enum ScreenState{
  MAIN_SCREEN, 
  SCREEN_ONE,
  SCREEN_TWO
};

ScreenState screenState = MAIN_SCREEN;

bool buttonPressed;   //just to compile example
void setup() 
{
  // put your setup code here, to run once:
}

void loop() 
{
  switch (screenState)
  {
    case MAIN_SCREEN:
    //do main screen stuff
    break;
    case SCREEN_ONE:
    // do screen one stuff
    break;
    case SCREEN_TWO:
    //do screen two stuff
    break;
  }
  
  if (buttonPressed && screenState == MAIN_SCREEN)
  {
    screenState = SCREEN_ONE;
  }
}