bool
Description
A bool holds one of two values, true or false. (Each bool variable occupies one byte of memory.)
Syntax
bool var = val;
Parameter Values
- var: variable name.
- val: the value to assign to that variable.
Example Code
This code shows how to use the bool datatype.
int LEDpin = 5; // LED on pin 5
int switchPin = 13; // momentary switch on 13, other side connected to ground
bool 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
- Language : array
- Language : boolean
- Language : byte
- Language : char
- Language : double
- Language : float
- Language : int
- Language : long
- Language : short
- Language : size_t
- Language : string
- Language : String()
- Language : unsigned char
- Language : unsigned int
- Language : unsigned long
- Language : void
- Language : word
- Language : constants
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables.
Additionally, some links direct to products from our own brand, DIYables.