Arduino refrence example program

I can't understand this program which i was reading about in the boolean data type found on this page: Arduino - Home

please i need explanation so that i can understand it :slight_smile:

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
  }
}

A boolean can be true or false, that's all.

Like this:

boolean sensor_active = true;
...
if (sensor_active)
{
  // the sensor is active
}

There a operators, which can be used. Like the NOT-operator (the '!').

if (!sensor_active)
{
  // the sensor is not active !
}

It is even allowed to make true false, and false true, using the NOT-operator.

sensor_active = !sensor_active;

So all you have to do, it say "NOT", if you see an exclamation mark.