digitalWrite() Parameters and Best Practices

Is there better documentation for digitaWrite() than the Arduino Reference?

It does not seem to say what digitalWrite's parameters are. I am specifically asking about parameter 2, value. It says value can be HIGH or LOW which are #define macros.

I have checked other sources and some places people are saying it is a byte, others are saying it is a bool.

I would like to pass a state variable to digitalWrite(), but I don't know what type of variable to store the data in.

What are best practices? Am I not supposed to want to pass a state variable? Am I supposed to only use the HIGH or LOW macro and do my logic wrapped around the function call?

I would like to pass a state variable to digitalWrite(), but I don't know what type of variable to store the data in.

A pin can only high or low and a with high being 1 and low being 0.

So you can use any simple type that can take these values.

Mark

Thee_Captain:
Is there better documentation for digitaWrite() than the Arduino Reference?

It does not seem to say what digitalWrite's parameters are. I am specifically asking about parameter 2, value. It says value can be HIGH or LOW which are #define macros.

I have checked other sources and some places people are saying it is a byte, others are saying it is a bool.

I would like to pass a state variable to digitalWrite(), but I don't know what type of variable to store the data in.

What are best practices? Am I not supposed to want to pass a state variable? Am I supposed to only use the HIGH or LOW macro and do my logic wrapped around the function call?

Why would you want to pass a state variable? Digital pins can only be HIGH or LOW, so that's why that's why the special values are defined for it. Other values will work, but why would you use them? Some arbitrary state value isn't going to make any sense.

I suspect he's asking about what data type should be used to hold a HIGH or LOW.

Use byte.

In arduino-land, there's no benefit to a bool over a byte (both take a whole byte). That said, storing them as int's would still work as they would be converted to a byte when passed to the digitalWrite() function - it would just waste an extra byte of memory.

@jiggy was a bit harsh...
You may for example - want to set the output bit with the return value from a function...

bool myFunction() {
   bool aValue;
     :::
   return avalue;
}
     :::
digitalWrite(thePin, myFunction());

Any ZERO value will be a LOW, any other value sets HIGH

Unfortunately, parameter and return types are not consistently documented in the Arduino documentation. There are several long-standing requests to fix this. I don't have the ability to edit the library reference pages, so I won't be able to do anything about the issue as it occurs in that documentatation, but everyone has the ability to submit pull requests to improve the Language Reference content, where the digitalWrire() documentation is found. I plan to go through the entire Language Reference and document every parameter and return type, as well as verifying that the existing parameter and return type documentation is correct and complete (sometimes the type differs from one hardware package to another). As a start towards that goal, I established a standardized format for documenting this information, implemented that format in all the Language Reference pages which currently have parameter or return type documentation, and submitted a pull request:

Unfortunately, that pull request has not yet been merged, blocking me from any further progress on this important project for now. Hopefully someone will get the time to merge it soon.

lastchancename:
Any ZERO value will be a LOW, any other value sets HIGH

I don't think it's good practices to assume the values of HIGH and LOW. bool should only be used for true/false values.

Thank you everyone for your helpful comments. From the feedback here and what I've read online, I am going to use a byte. It sounds as if this is what the function parameters are asking for.