Boolean

From Microduino Wiki
Jump to: navigation, search

Boolean

A Boolean variable has two values, true or false.(each Boolean variable takes up one byte of memory).

  • Example
int LEDpin = 5;       // LED is connected with pin 5.
int switchPin = 13;   // A pin of the switch is connected with pin 13, and the other is connected to the ground. 
 
boolean running = false;
 
void setup()
{
  pinMode(LEDpin, OUTPUT);
  pinMode(switchPin, INPUT);
  digitalWrite(switchPin, HIGH);      // Open the pull-up resistor. 
}
 
void loop()
{
  if (digitalRead(switchPin) == LOW)
  {  // Press the switch - pull the pin to the high potential 
    delay(100);                        // By delaying, filter the clutter produce by the jitter of the switch. 
    running = !running;                // Trigger variable running.
    digitalWrite(LEDpin, running)      //Light LED.
    }
  }

[Return to Arduino Syntax Manual]