1 want to use 1 led in the lower light range and the same led in the upper light range.
1 pin 100 ohm resistor to the led
1 pin 500 ohm resistor to the same led (thus more dimmed)
I thougt that
analogwrite ( some pin, 0 )
analogwrite ( the other pin, range 1-255 )
would do the case, however it is not. Looks like the pin with the 0 value is providing a path to ground?
Anyone willing to enlighten me and maybe give a hint how to solve this? I tried adding a diode for each pin , that works but the voltage drop over the diode is too high to get the maximum led output.
The inactive pin should not be analogWrite anything, but should be pinMode INPUT. Then it will be high impedance, and will neither source nor sink current. But Idahowalker is right. AnalogWrite is designed to give you variable average voltage, so it seems one pin should be enough.
The spread is not enough. The light is used to drive a photoresistor and if I play the whole range on 1 pin eighter i'm missing range in the lower end or on the upper range. That is why i thought about 2 pins with different current limiting resistors. This works wel if I do 1 led per pin.
100 Ohm is a bit low for the average led, but you, probably, have a high-current led...
Anyway: a output can deliver enough current to drive a LED (not a 3W type )
analogWrite(PWM_PIN,PWM_Value) will drive the LED correct if you connect the anode of the led to the PWM_PIN with a resistor of 3V/LED-current (220 Ohm is normal) and the kathode to Ground.
Check if the output is capable to output PWM signals, not every processor or output supports that.
Yes; I use the whole range from 1-255. But a (my) photoresistor is not regular to the value of analogwrite. From 0 to 100 the resistance value of the PR goes up like a rocket and after 100 to 255 is flattens out. Bij putting a different resistor (I said 100 and 500 but in reality I use a variable register (1-1000 ohm)) and different code in the range 0-100 and 100-255. This way I can smoothen it out. This works very well with 1 led / pin but if I put the same led connected to 2 pins and toggle one of these pins, it doesn't work as expected. If I regulate 1 resister it regulates the current for both. I'm gonna try to create kind of a relay to the led.
Can you please post a drawing of your circuit, including the LDR?
A hand drawn image will be fine.
An image of your project would be of help too.
A copy of your code will be appreciated.
Precisely as you would expect. You refer to an LDR - its response is anything but linear and a 2.5:1 ratio really makes quite little difference in the resistance just as it corresponds to only a minor change in perceived brightness.
You do realise do you not, that if you have a resistor connected to each of two pins and the same LED, when you pull one of those pins LOW as an an output, it will sink current and there will be less for the LED?
You need to not write such a pin LOW, but set it to INPUT to disable it.
Yes, I didn't know this when I started this topic but in reply 4 [ShermanP] wrote this allready. However it didn't work when I tested it ...
So wrong answer? No, correct answer but I had to learn that you have to set the pin, after it has become an input, explicitely to output again before the next analogwrite. I thought that analogwrite took care of these things itself but it does not (I actually use an esp8266 d1)