Skip to content

Commit a1ceb3b

Browse files
committed
Document bool data type
Previously only Arduino's type alias, boolean was documented. In this case it's arguable that the benefits of a slightly more descriptive type name outweigh the disadvantages of using a non-standard type. For that reason documenting bool and recommending its use instead of boolean is desirable.
1 parent 55417c3 commit a1ceb3b

File tree

2 files changed

+83
-41
lines changed

2 files changed

+83
-41
lines changed
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: bool
3+
categories: [ "Variables" ]
4+
subCategories: [ "Data Types" ]
5+
---
6+
7+
8+
9+
10+
11+
= bool
12+
13+
14+
// OVERVIEW SECTION STARTS
15+
[#overview]
16+
--
17+
18+
[float]
19+
=== Description
20+
A `bool` holds one of two values, `true` or `false`. (Each `bool` variable occupies one byte of memory.)
21+
22+
23+
[%hardbreaks]
24+
25+
--
26+
// OVERVIEW SECTION ENDS
27+
28+
29+
30+
31+
// HOW TO USE SECTION STARTS
32+
[#howtouse]
33+
--
34+
35+
[float]
36+
=== Example Code
37+
// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄
38+
This code shows how to use the `bool` datatype.
39+
40+
[source,arduino]
41+
----
42+
int LEDpin = 5; // LED on pin 5
43+
int switchPin = 13; // momentary switch on 13, other side connected to ground
44+
45+
bool running = false;
46+
47+
void setup()
48+
{
49+
pinMode(LEDpin, OUTPUT);
50+
pinMode(switchPin, INPUT);
51+
digitalWrite(switchPin, HIGH); // turn on pullup resistor
52+
}
53+
54+
void loop()
55+
{
56+
if (digitalRead(switchPin) == LOW)
57+
{ // switch is pressed - pullup keeps pin high normally
58+
delay(100); // delay to debounce switch
59+
running = !running; // toggle running variable
60+
digitalWrite(LEDpin, running); // indicate via LED
61+
}
62+
}
63+
----
64+
65+
--
66+
// HOW TO USE SECTION ENDS
67+
68+
69+
// SEE ALSO SECTION STARTS
70+
[#see_also]
71+
--
72+
73+
[float]
74+
=== See also
75+
76+
[role="language"]
77+
* #LANGUAGE# link:../../../variables/constants/constants[constants]
78+
79+
--
80+
// SEE ALSO SECTION ENDS

Language/Variables/Data Types/boolean.adoc

+3-41
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ subCategories: [ "Data Types" ]
1717

1818
[float]
1919
=== Description
20-
A `boolean` holds one of two values, `true` or `false`. (Each `boolean` variable occupies one byte of memory.)
20+
`boolean` is a non-standard type alias for link:../../../variables/data-types/bool/[bool] defined by Arduino. It's recommended to instead use the standard type `bool`, which is identical.
2121

2222

2323
[%hardbreaks]
@@ -28,44 +28,6 @@ A `boolean` holds one of two values, `true` or `false`. (Each `boolean` variable
2828

2929

3030

31-
// HOW TO USE SECTION STARTS
32-
[#howtouse]
33-
--
34-
35-
[float]
36-
=== Example Code
37-
// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄
38-
This code shows how to use the `boolean` datatype.
39-
40-
[source,arduino]
41-
----
42-
int LEDpin = 5; // LED on pin 5
43-
int switchPin = 13; // momentary switch on 13, other side connected to ground
44-
45-
boolean running = false;
46-
47-
void setup()
48-
{
49-
pinMode(LEDpin, OUTPUT);
50-
pinMode(switchPin, INPUT);
51-
digitalWrite(switchPin, HIGH); // turn on pullup resistor
52-
}
53-
54-
void loop()
55-
{
56-
if (digitalRead(switchPin) == LOW)
57-
{ // switch is pressed - pullup keeps pin high normally
58-
delay(100); // delay to debounce switch
59-
running = !running; // toggle running variable
60-
digitalWrite(LEDpin, running); // indicate via LED
61-
}
62-
}
63-
----
64-
65-
--
66-
// HOW TO USE SECTION ENDS
67-
68-
6931
// SEE ALSO SECTION STARTS
7032
[#see_also]
7133
--
@@ -74,7 +36,7 @@ void loop()
7436
=== See also
7537

7638
[role="language"]
77-
* #LANGUAGE# link:../../../variables/constants/constants[constants]
39+
* #LANGUAGE# link:../../../variables/data-types/bool/[bool]
7840

7941
--
80-
// SEE ALSO SECTION ENDS
42+
// SEE ALSO SECTION ENDS

0 commit comments

Comments
 (0)