GPIO output default state?

This is a total newbie question…if I have a program that periodically sets one of the digital outputs HIGH via a “while” loop, does the pin automatically go back to LOW when the loop is no longer true?

Here’s an example snippet of what I’m doing:
while(secaccum>=57 && secaccum<=63 && Time.hourFormat12()!=6)
digitalWrite(correction, HIGH);

Currently, at the end of my void(loop), I have digitalWrite(correction, LOW) so that whenever the while loop is NOT true, the pin is off, but I wasn’t sure if that was really necessary.

Thanks for your input!

You are setting a state. A pin’s state does not have a programming scope like a variable does. (You could consider the state to be like a global variable, I suppose, in that it has global scope!) An output pin is HIGH until you set it LOW and v.v. Where you do this in your code is immaterial.

You have to program to let it go to LOW or it will just remain at the current state (HIGH) :slight_smile:

Thanks, that’s what I thought! I knew that typically variables stay set (as you would want them to!), but I’ve never dealt with microcontroller outputs before.

1 Like