Go Down

Topic: pin output level after analogWrite() on non PWM pins (Read 1 time) previous topic - next topic

Coding Badly

Quote
the more I began to wonder does the current analogWrite() behavior on non pwm pins really make sense?


Doesn't make sense to me.  The behaviour seems very arbitrary.

Quote
I can only assume that there must be other cases where the current behavior is desired.


My understanding of Arduino API is that, if possible, every function call should have some affect so the artist has feedback.  In other words, turning the LED full on at some arbitrary threshold is better than doing nothing so the artist at least knows the program is running.

Quote
Does anybody have any real world experience or examples where the existing behavior works for them and is desired?


I don't and I cannot imagine any.

I agree with RuggedCircuits and retrolefty with a small exception.  If possible, at compile time, an error should be generated.

bperrybap



I agree with RuggedCircuits and retrolefty with a small exception.  If possible, at compile time, an error should be generated.



Yep. That would be nice. But it really isn't a compile time thing that can be detected.
analogWrite() can be passed a variable parameter at runtime given the way the arduino APIs are defined
and there is no way to catch that at compile time.

Anyway, I've moved on by simply not worrying about it and writing code that detects if the pin
supports PWM and then making the output work the way I want/need it to work.

--- bill

Go Up