boolean

[Data Types]

Description

A boolean holds one of two values, true or false. (Each boolean variable occupies one byte of memory.)

Example Code

This code shows how to use the boolean datatype.

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

  • LANGUAGE String()

  • LANGUAGE array

  • LANGUAGE byte

  • LANGUAGE char

  • LANGUAGE double

  • LANGUAGE float

  • LANGUAGE int

  • LANGUAGE long

  • LANGUAGE short

  • LANGUAGE string

  • LANGUAGE unsignedChar

  • LANGUAGE unsignedInt

  • LANGUAGE unsignedLong

  • LANGUAGE void

  • LANGUAGE word