0

A byte stores an 8-bit unsigned number, from 0 to 255.

I can understand the following line:

byte b = B10010;  // "B" is the binary formatter (B10010 = 18 decimal) 

But I also saw a use such as:

volatile byte state = LOW;

What does the last line mean here? Is that special for Arduino? I mean LOW is not a 8 bit unsigned number. LOW is not a number here.

3 Answers 3

4

There is probably somewhere else, like this:

#define LOW 0

Which means the pre-processor turns your line from this:

volatile byte state = LOW;

into this:

volatile byte state = 0;

There is nothing arduino-specific here, just the use of standard C/C++ features.

2

It is common practise in C/C++ to define certain much-used constants at the beginning of the code.

#define true 1

this means that every time you write true in your code, the compiler will see it as 1.

The arduino IDE comes with a few constants predefined:

  • true = 1
  • false = 0
  • HIGH = 1
  • LOW = 0
  • ...
2
  • in C++ true and false are already keywords, why would one try to #define them?
    – jfpoilpret
    Commented Jan 25, 2017 at 7:28
  • @jfpoilpret Perhaps if one is not using C++ ... Commented Mar 21, 2021 at 19:34
0

In the same way that you can do

int blarb = 12;
#define wibble 73

you can do

int FOO = 73;
#define BINKY 99

or even

int LOW = 0;
#define HIGH 1

So in the line

volatile byte state = LOW;

someone has created some sort of numerical constant with the name LOW.

You can read all about various constants provided for you here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.