Scale-N

Scale-N
Arduino
Componenten
Rollend Materieel
Naslag
Onderdelen
Wissels
Basis Electronica
Symbols Electronica
Programming Arduino
AKS
DCC++
DR5000













































Programming Arduino - bool

Boolean
Size 1 byte
Range 0 to 1

A 'bool' holds one of two values, true or false. Each Boolean variable occupies one byte of memory.
false=0 | true=1

Logical AND (&&) results in true only if both operands are true.
Logical NOT (!) results true if false and false if true
Logical OR (||) results in true if one of the operands is true.

Declaration:
// declaration of variable with type boolean and initialize it with false
bool val = false ;
// declaration of variable with type boolean and initialize it with true
bool state = true ;

Code 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);
// turn on pullup resistor
digitalWrite(switchPin, HIGH);
}
void loop()
{
if (digitalRead(switchPin) == LOW)
{
// switch is pressed - pullup keeps pin high normally
// delay to debounce switch
delay(100);
// toggle running variable
running = !running;
// indicate via LED
digitalWrite(LEDpin, running)
}
}