boolean
holds one of two values, true or false. (Each boolean variable occupies one byte of memory.)
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
int LEDpin = 5; // LED to pin 5
int switchPin = 13; // One end of the push button switch is connected to pin 13 and the other end is connected to ground
boolean running = false ;
void setup()
{
pinMode(LEDpin, OUTPUT);
pinMode(switchPin, INPUT);
digitalWrite(switchPin, HIGH); // Enable pull-up resistor
}
void loop()
{
if (digitalRead(switchPin) == LOW)
{ // Press the switch
delay(100); // Delay time (to prevent switch bounce)
running = !running; // Toggle LED control variable
digitalWrite(LEDpin, running) // Controlling LEDs
}
}
|
See also
- constants
- boolean operators
- Variable Declaration
Language Reference Home
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.