Is the "Fade" example digital or analogic?

Hi all,

sorry if I am asking a stupid question, but I am beginning with Arduino and my knowledge about about electronic are very poor. I finished the Fade example (http://arduino.cc/en/Tutorial/Fade example) but I don't understand why it belongs to the "Analog I/O" category when actually it uses a digital output:

"Connect the anode (the longer, positive leg) of your LED to digital output pin 9"

Is it analogic or digital?

Hi jero

When you look at the LED, the brightness varies between off and fully bright. The brightness appears to take on a [u]range[/u] of different levels, not just "off" and "on". For this reason, you can think of it as analog.

The way the program does this is by switching a digital signal on and off very quickly (too quickly to see) and changing the ratio of the on time to the off time. The more on time, the brighter the LED appears to be. So the voltage being fed to the LED is either +5V or 0V, no values in between. In that sense, it is a digital signal.

Regards

Ray

Thanks a lot Ray,

that was a very good explanation!

Cheers,
Jero.

If I may add to this:

The more on time, the brighter the LED appears to be. So the voltage being fed to the LED is either +5V or 0V, no values in between. In that sense, it is a digital signal.

But depending on the ratio of on time to off time, average voltage is a value between 0 and 5V, so in that sense it's analog. (0% on time = 0V, 100% on time = 5V, 50% on time = 2.5V on average.)

http://arduino.cc/en/Reference/AnalogWrite

Thanks JimboZA for the reference to the analogWrite() method.

jero_at_arduino: but I don't understand why it belongs to the "Analog I/O" category

Perhaps it doesn't? But that's where it is and I doubt if it is going to be moved.

It won't be the only inconsistency in the Arduino universe.

...R

Well although it uses a digital pin, it uses the analogWrite() method, so it has a "leaning" towards the analog world. I'd personally see it as closer to analog (a sort of pseudo-analog) than pure digital although it is pure digital.

It's an old complaint. The arduino folks (or was it originally the Wiring people?) really should have named the function pwmWrite() to more accurately describe what the function actually does, but felt that beginners would be more comfortable with the analogWrite() name.

Yes, it's digitalic.

jero_at_arduino: I finished the Fade example (http://arduino.cc/en/Tutorial/Fade example) but I don't understand why it belongs to the "Analog I/O" category when actually it uses a digital output:

By the other explanations I know you've got it but here's another way to think about it, comparing the binary to analog worlds. Digital is actually not a very good word to use -by- -itself- on this topic so I'll also use the word binary as appropriate. Digital (typically) means more of a way to 'switch things between specific analog levels.' Binary means 'on or off.'

Humans live in an analog world. That's a given. We may turn a light switch on or off but except for blinding white light or a sealed darkened room we always perceive vision in terms of analog variations of brighter and dimmer.

Most digital based computers live in a binary world. Well, actually at it's lowest transistor and gate levels it's still analog but the -intent- is that they -behave- binarily so we can -work- with them in a binary/digital manner.

Using a PWM pin as an analog output -would- normally mean an -infinitely- variably adjustable output, such as a potentiometer making an LED brighter or darker. However Arduino PWM output doesn't have infinite steps, not even very many really. [1] But the step increments -are- -small- enough that as the steps change from one to the next the analog-based human eye is happy enough to -perceive- it as an 'analog' increment or decrement in light or sound or whatever the pin is controlling.

The PWM-capable pins are extremely versatile and powerful. They can be used as -digital- to set the volume level of an audio signal to a particular -specific- level. They can be used as analog, by incrementing the register to gradually 'fade' a light from one level to another -as- -if- it were being adjusted by a pot. Or actually they can even be used as binary-digital, by setting a register to 0 or 255 to turn something fully 'on' or 'off.'

So the correct final answer is yes, Virginia, there -is- a Santa Claus, and a PWM pin is -either- digital or analog depending on how you want to use it, or more accurately how you want to think about it for a particular use.

[1] Example, here's a wikipedia page that demonstrates the analog -effects- of human -perception- of color as regards resolution. Scroll down a bit and on the right side of the screen you'll see a few images of the same picture at different color depths. http://en.wikipedia.org/wiki/Color_depth

Decent explanation. However I still think they screwed up naming it analogWrite(), should have been named pwmWrite();