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.

asked Jan 24, 2017 at 13:47

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.

answered Jan 24, 2017 at 13:59
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
  • ...
answered Jan 24, 2017 at 14:25
2
  • in C++ true and false are already keywords, why would one try to #define them? 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.

answered Jan 24, 2017 at 13:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.