All I want is a Boolean variable

I have a piece of code:

void setup() 
{
  // initialize flag for new press of button
  boolean newPress = true;

  // nominate port 2 for sensing button state
  int buttonStatePort = 2;

  // nominate port 13 for powering LED
  int ledPowerPort = 13;
}

void loop() 
{
  // loop to check for button press
  while (newPress == true)
  {
    // check the state (high or low) of the button port
    if (digitalRead(buttonStatePort) == HIGH)  // button is pressed
    {
      // escape the loop
      newPress = false;
    }
    else
    {
      // wait a while and check again
      delay(10);
    }
  }

  // assert: at this point the button has been pressed and newPress is false

  // go on with further processing

}

Any attempt to compile this using Arduino 1.6.9 is greeted with

latchingRelay:16: error: 'newPress' was not declared in this scope

   while (newPress == true)

          ^

latchingRelay:19: error: 'buttonStatePort' was not declared in this scope

     if (digitalRead(buttonStatePort) == HIGH)  // button is pressed

                     ^

exit status 1
'newPress' was not declared in this scope

I have read a variety of posts on this forum, and I have Evans' booklet arduino programming notebook, and I can't figure out how to #include a C++ header file (or even which one to #include).

I have been unable to decipher the process of creating an header file in the Arduino environment. Creation of types.h results in a new folder called types.h containing a file types.h.ino which remains steadfastly unrecognized.

In short, I find myself unable to do such a simple thing as to have a Boolean variable to use as a flag.

It must be able to be done.

Would someone be so kind as to show me a simple way to make this work in the Arduino language subset, or how to extend the subset to make it work.

Thank you

Define the variables outside of setup or loop and they'll be global.

Maybe this would work

  // initialize flag for new press of button
  boolean newPress = true;

  // nominate port 2 for sensing button state
  int buttonStatePort = 2;

  // nominate port 13 for powering LED
  int ledPowerPort = 13;

void setup() {
/*You still need to set up your pins as inputs and outputs here with pinMode.
*/
}

void loop()
{
  // loop to check for button press
  while (newPress == true)
  {
    // check the state (high or low) of the button port
    if (digitalRead(buttonStatePort) == HIGH)  // button is pressed
    {
      // escape the loop
      newPress = false;
    }
    else
    {
      // wait a while and check again
      delay(10);
    }
  }

  // assert: at this point the button has been pressed and newPress is false

  // go on with further processing

}

The topic you need to read about is the 'Scope' of a variable.

I might have one extra Boolean available - if you can't find one, happy to send it to you :)

(Joke aside your pb is indeed scope as you declare newPress as a local variable of the setup() function and then try to use it in the loop() function where it is unknown)

Thanks folks. INTP's suggestion solved it. All contributions appreciated - especially a little humour on a rainy day ;)