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.

floppy380
  • 245
  • 4
  • 10

3 Answers3

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
  • ...
Janw
  • 294
  • 1
  • 9
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.

Mark Smith
  • 2,181
  • 1
  • 10
  • 14