The method help says that After a call to analogWrite(), the pin will generate a steady square wave of the specified duty cycle until the next call to analogWrite() (or a call to digitalRead() or digitalWrite() on the same pin).
I am just doing a basic example for my kids on how the Arduino works.
I don't understand why I can't just set analogWrite in the setup loop.
Why do I have to put it in the loop method and have it called over and over?
The help file says
After a call to analogWrite(), the pin will generate a steady square wave of the specified duty cycle until the next call to analogWrite() (or a call to digitalRead() or digitalWrite() on the same pin).
For all we know, you did something else in loop() that cancelled the analogWrite. That's why we ask you to copy and past the code you actually used, not just vaguely describe it.
However the in the first block of code the LED only flashes for a very brief moment.
(This is my point, I would assume it would just stay on!)
In the second block of code, the LED stays on because its in a loop which continuously calls analogWrite.
This is my question, why doesn't the first block of code keep the LED on continuously until some other call to that pin. Just like it says in the help file.
I just tried it in the Arduino IDE 1.6.5 and it works fine as expected.
so I just went back to AtmelStudio and tried it again, still only a flash.
Then I tried to compile it in the release configuration and it works.
It is something to do with the Debug configuration.
I turned off 'Report Digitals' and its working fine.
Sorry to bother you all.
It must be when the 'Report Digitals' dialog loads it resets the pins.
It must be when the 'Report Digitals' dialog loads it resets the pins.
It would have to make a call to pinMode() to make the pin input, so that it could then meaningfully call digitalRead(), which would, of course, turn off PWM on that pin.