Can digitalWrite be used in Global or Setup?

Got it.

So has to be in setup or loop or some other function.