Hi everyone,
I have a real basic question about dimming LEDs using analogRead/analogWrite. I have zero programming experience, so please no laughter as my vocabulary in regards to this subject may be a little caveman-ish.
I am having no luck getting the code right for what I am trying to accomplish.
Do I need an input pin for analogRead()? Or can it be a int value?
I am using a TFT LCD screen, and have all my color channels set to a int Max_bright between 0-100.
What I am trying to do is analogRead that value, and then analogWrite to the appropriate pwm channel.
Simplistic code example might help clarify what I am talking about:
int white_leds = 7;
Int white_max = 100;
Int ledlevel = 0;
void setup()
{
pinMode(white_leds, OUTPUT);
}
void loop()
{
ledlevel = analogRead(white_max); //when white_max=100, analogRead=1023???
analogWrite(white_leds, ledlevel/4); //converts the read 1023 to the write 255??
}
This is basically how I have been trying to dim the LEDs, but I might be missing something because I've been trying to get similar code working, but I'm stuck.
I want it to read the value of white_max. I might be missing something there. When white_max = 100 then the read is 1023...99 then the read is 1012...98 the read is 1002 ect.
I might be wrong thinking this behaves in this way.
Thanks for a push in any direction.


