User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







arduino:data_types:booleanvariables

Table of Contents

boolean

A boolean holds one of two values, true or false. (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

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
arduino/data_types/booleanvariables.txt · Last modified: 2024/02/16 01:04 (external edit)

Impressum Datenschutz