Let me smack myself real quick before I post again...*smack*That's odd. Your pot is 20k, so if center tapped, that would be a 10k load on your I/O pin for 330uA current - if the I/O pin could make it to 3.3v!
It's actually quite easy, check this steps:The only problem with that is doing the math in the microcontroller to set the duty cycle[...]
The formula required to do this results in a pretty big loss of resolution. There's probably a better way of doing it, but I haven't figured one out yet. Thanks for the suggestion though
Interesting...I never thought of doing it like that. Good suggestion, I'll give it a shot and let you know how it goes.It's actually quite easy, check this steps:
----
activated led is led_1 by default
compare adc to 512
if adc value is lower go to "rotate_adc"
else (if adc value is 512 or higher) activated led is led_2
and substract 512 from the adc value so range becomes 0 - 511
rotate_adc:
rotate left adc so the range 0 - 511 becomes 0 - 1023
----
tadaaaa
It took me a full 8 minutesI was wondering when you were going to catch the loss in resolution.
I'm back to working this through, and I'm doing it similar to the way you described here. It's a much more efficient way of doing it compared to how I was. My method required a lot of division and floating point math to get the resolution halfway decent. This resulted in a VERY slow program. With your method, however, everything is done with bitwise operations, making it much faster while still giving good resolution.haha sorry, I actually was thinking about it too but it's eeeeasy with uc to do all that stuff and more. But you see, I usually just answer with a general idea and hope the recipient develops it to their need.
Look:
----
get the adc reading
compare it to 512
if it's the same or higher goto is_led_2
is_led_1:
active led is led 1
rotate left adc
two's complement adc
return to main
//this would make the lower half of the pot to control led 1 with 0v being full scale and 1/2 vdd being off
is led_2:
active led is led 2
substract 512 from adc
rotate left adc
return to main
//this would make the higher half of the pot to control led 2 with 1/2 vdd being off and vdd being full scale
----
The range would actually be 0-1022 but come on seriously it's only one bit to full scale and in 2 bits steps. 512 brightness steps instead of 1023 for a led is not at all noticeable!