0
votes

I am new in Arduino. I found a code that uses digitalWrite() and pinMode(). What I know so far these functions are used both to set the digital pins as input or output. Why the code that I found uses both of them instead of using one of them? Is it any difference between them?

1

1 Answers

2
votes

pinMode is setting whether the pin is an input or output

If the pin is set to output, it will be driven either high or low depending on what you digitalWrite to it

If the pin is set to input, whether is is high or low (or floating inbetween) depends on what is happening externally.

If you do a digitalWrite to an input pin, it wont take effect until you set the pinMode to output