digitalWrite vs digitalRead

looking at the wiring_digital.c of 1.8.13 I find following:

What is the reason why digitalWrite takes an uint8_t val as parameter (HIGH or LOW)

void digitalWrite(uint8_t pin, uint8_t val)

but the return value of digitalRead is defined as int?

int digitalRead(uint8_t pin)

isn't that somehow inconsistent? Or is there any reason for that?

Yes, it's inconsistent. I don't expect there is a good reason.

(The type for a true/false, 1/0, HIGH/LOW value should be 'bool' instead of 'int' or 'uint8_t'.)

Yes, it is inconsistent. It should return an enum HIGH or LOW, neither of which should necessarily be taken to mean true or false.

Why an enum? Why not just true or false?

-jim lee

Because HIGH is not true.
It's HIGH.

Imagine you've got a switch wired with a pullup.
If the switch is closed, it is LOW.

Should LOW be true?

I think because of analogWrite(), it is more than bool they kept it at int
I find that many things in the arduino source code use int or byte rather than bool. Don't really know why. Simplicity? Consistency? maybe..

Accuracy?

dunno

Non sequitur?

where would you need accuracy in analogWrite() or digitalWrite();

Accuracy of nomenclature.

It is HIGH, LOW, RISING, FALLING I think, but haven’t seen any use of the last 2 maybe a placeholder for the future?

I guess its from the outlook you are used to.

To someone used to electronics, it would make sense to call it HIGH, LOW.

My background is software and to me its all true or false.

-jim lee

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.