Control LED and audio with Arduino and one POT?

Hy everyone, Is there any way to control led brightness and volume with one POT and Arduino? When music is louder(control volume with POT) how to change led brightnes according to the volume of music using the same pot and Arduino?

Do you know how to [u]dim an LED[/u]?

Do you know how to [u]read an analog input[/u]?

If the pot isn't already wired-up and working as a volume control, [u]here[/u] is something I found about how to wire it up.

Note that the load impedance should be greater then the resistance of the pot, so a 1K or 10K pot won't work properly with 23-Ohm headphones.

The "output" of pot can go into an amplifier and into an Arduino analog input that's [u]biased[/u] to allow AC input.

With the input biased, the ADC will read about 512 with silence. Subtract-out the bias in software and you can deal with the negative values by using the absolute value or simply throwing-out the negative values.

As a "first pass" you can [u]map()[/u] the bias-corrected 0-512 analog reading to 0-255 for PWM LED brightness.

You'll probably have to adjust the mapping depending on how the "loudness" correlates with your ADC readings.

And, because the audio "wave" is continuously varying and it crosses through zero twice per cycle, you might want to take readings over a 20-100 millisecond time period and extract the peak. If you don't do that, you won't see full brightness, because your eye won't react to the peaks (the same way that PWM dimming works to fool the eye).