• In that case I'd really consider adding functions like setRelay and getRelay - it'd allow you to do other things at a later date like logging messages when the relay turns on and off, or turning an indicator light on and off as well.

    While it does add some overhead, it could well be worth it for flexibility/readability (for instance what happens if you change to use a relay module that turns on when 0v is applied).

    To be honest your relay case is probably a pretty good example of why a digitalRead that doesn't change state is a really bad idea on Arduino. While it would work most of the time, it could very easily inexplicably return the wrong result some of the time, which would cause some very strange bugs.

    What does everyone else think about readOutputValue? Worth it, or just a bit confusing?


Avatar for Gordon @Gordon started