Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
The other person said that you should look at the Arduino Core code, while I think it's a good idea to an extent, there's a lot of code that's really specialized (looking at all the #defines) and code that's written to "protect users" (I really don't know how to word this). Go look at digitalWrite, it makes sure the pin you're using is a valid pin and it turns off any PWMs. I don't think it's even possible to write an invalid value to the output register, and you don't always have to check for a PWM if you never set up a PWM in the first place (you'd disable the peripheral function when you set the pin up as an input/output).