blob: 3bbe72a5dc3de867aa532043221a678ec7d9aab2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
.. _arduino-booleanvariables:
boolean
=======
A **boolean** holds one of two values,
`true <http://arduino.cc/en/Reference/Constants>`_ or
`false <http://arduino.cc/en/Reference/Constants>`_. (Each boolean
variable occupies one byte of memory.)
Example
-------
::
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
}
}
See also
--------
- `constants <http://arduino.cc/en/Reference/Constants>`_
- `boolean operators <http://arduino.cc/en/Reference/Boolean>`_
- `Variable Declaration <http://arduino.cc/en/Reference/VariableDeclaration>`_
|