Search code examples
arduino-esp8266

digitalWrite best practice in Arduino


I have a loop checking the status of a sensor. If it's in one state, I light a LED using digitalWrite (1,HIGH), otherwise, I write LOW. This happens in a tight loop many times a second.

Is it fine to write so many times, or is it better practice to set a flag and only write if the flag has changed?


Solution

  • It shouldn't be a problem for the board. You could also add a short delay at the end of the loop (delay(5);)