Arduino

Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

Blog » | Forum » | Playground »

Reference Language (extended) | Libraries | Comparison | Board

## boolean variables

boolean variables are hold one of two values, true and false.

#### Example

    int LEDpin = 5;       // LED on pin 5
    int switchPin = 13;   // momentary switch on 13, other side connected to ground

    boolean running = false;

    void setup()
    {
      pinMode(LEDpin, OUTPUT);
      pinMode(switchPin, INPUT);
      digitalWrite(switchPin, HIGH);      // turn on pullup resistor
    }

    void loop()
    {
      if (digitalRead(switchPin) == LOW)
      {  // switch is pressed - pullup keeps pin high normally
        delay(100);                        // delay to debounce switch
        running = !running;                // toggle running variable
        digitalWrite(LEDpin, running)      // indicate via LED
      }
    }

#### See also

- constants
- boolean operators

Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

Edit Page | Page History | Printable View | All Recent Site Changes