Quick Question: Setting Function Argument as a variable

Is it possible to do something like…

digitalWrite(pin, High);

If (pin = High)
{

Stuff to do

}

?

Currently, I’m using a dummy variable:

digitalWrite(pin, High);
p = 1;

If (p = 1) 
{

Stuff to do

}

Thanks!

Yes, that is how you pass a variable into a function so the function can take the appropriate action.

I’m not quite sure what you are trying to do here, but I see one issue. Keep in mind the difference between = and == (assignment and equality test)

/mike

I agree with nList. I understand this is an example but your logic is flawed.

In this scenario, you really don’t need an if statement. Just put your “stuff to do” after setting the pin. No need for a comparison.

n1ist:
I’m not quite sure what you are trying to do here …

I believe he wants to set an output pin (perhaps at multiple places in code) and later determine it's output state w/o having to use a variable as an intermediate. The answer is to query the HW port register as described here ...

http://stackoverflow.com/questions/6160 … ode-output

Your observation of = and == should be noted as well.

Mee_n_Mac:

n1ist:
I’m not quite sure what you are trying to do here …

I believe he wants to set an output pin (perhaps at multiple places in code) and later determine it's output state w/o having to use a variable as an intermediate. The answer is to query the HW port register as described here ...

http://stackoverflow.com/questions/6160 … ode-output

Your observation of = and == should be noted as well.

Thank Mee_n_Mac! Thats what I wanted! Sorry for the lack of clarity. I forgot to use the comparison equals in my example.

Thanks again.