It's stupid because the PWM timer is being wasted as it is being use to regulate the pulsation of 0 volts at 490 hz.
It's a waste of the internal oscillator.
No it's not because it isn't doing anything or taking up any resource.
"You do not need to call pinMode() to set the pin as an output before calling analogWrite()."
There is nothing to say you can't do it. In fact what happens is a pin's direction (input or output) is set by a bit in a data direction register. Part of the analogWrite() function sets that bit, in other words it in effect does a pinMode() for you, so once you have used analogWrite() you can use digitalWrite() as well.
Grumpy_Mike:
what happens is a pin's direction (input or output) is set by a bit in a data direction register. Part of the analogWrite() function sets that bit, in other words it in effect does a pinMode() for you, so once you have used analogWrite() you can use digitalWrite() as well.
I see....I See!
So, the only reason, one don't have to set pinMode is because analogWrite does it for you automatically....
I doesn't suppose I should ask why it doesn't do that automatically when one calls digitalWrite(Pin_Number, HIGH), you would think the computer would know that "ofcourse you want it to be an output since you set it to high".
Regardless of that inconsistency, that means I can call digitalWrite(Pin_Number, LOW) after a analogWrite(Pin_Number, 128) then since analogWrite already set pinMode to OUTPUT.
Thanks
Still this internal favoritism is irregular and inconsistent.
A programming language should not behave like that, either they should all need the pinMode initializer, or they should have the ability to auto pinMode when a digitalWrite(XXX, OUTPUT) or analogWrite(XXX,255) is called.
A programming language should not behave like that, either they should all need the pinMode initializer,
You are wrong.
Are you saying that the analogWrite should refuse to work correctly if it's pin has not initialised?
As AWOL says there are other uses of digitalWrite() that are needed when the pin is an input.
There is no need to be outraged anyway, there isn't a computer language written without inconsistency or lack of orthogonality, I suspect you are just peeved that you made a mistake.