boolean

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

 

Example

int LEDpin = GREEN_LED;       // LED on pin 14
int switchPin = PUSH2;   // pin 5

boolean running = false;

void setup()
{
  pinMode(LEDpin, OUTPUT);
  pinMode(switchPin, INPUT_PULLUP);   // turn on internal pullup resistor
}

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

See also

 

Reference Home