Boolean

From Microduino Wiki
Revision as of 03:52, 18 August 2016 by Fengfeng (talk) (Created page with "Boolean<br> A Boolean variable has two values, true or false.(each Boolean variable takes up one byte of memory).<br> *'''Example'''<br> <pre style="color:green"> int LED...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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]