I would like to make a sketch that dims an LED at a range of 1024 levels. I know that i can use the analogWrite for dimming and it has the limitation of 256 levels, but i would like to know if there is a way around this
Yes
You can use TimerOne library.
// sketch_03_04_pwm
#include <TimerOne.h>
void setup()
{
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
Timer1.initialize(1000); //1kHz
Timer1.pwm(9, 512); //50%
Timer1.pwm(10, 255); //about 25%
}
void loop()
{
}
See programming Arduino Next steps. Page 66.
Period is 1000 uS or frequency is 1kHz.
Edit:
Affects pins 9 and 10, pin 9 here will have a square wave on it at 1kHz.
http://playground.arduino.cc/Code/Timer1
kookoo_gr:
dims an LED at a range of 1024 levels
Is this as a learning exercise? I'm struggling to image a situation where an observer would tell the difference between 256 levels let alone 1024 levels.
PeterH:
kookoo_gr:
dims an LED at a range of 1024 levelsIs this as a learning exercise? I'm struggling to image a situation where an observer would tell the difference between 256 levels let alone 1024 levels.
I agree.
If it is to do something like use an analogRead() value to set the brightness, use
the Arduino map() function to map the 0-1023 value to the 0-255 value used by analogWrite().
There is even an example of how to do this on the map() page:
--- bill
basically i want to make a project that uses a white LED strip in combination with a milky white plastic in order to create a white image so i can calibrate the images of a CCD camera. The range of 1024 is needed since various filters that i use need different levels of illumination and 256 levels won't cover this.
As you probably realize you can change the frequency in the "initialize" line and the width in the "pwm" line.
Timer1.initialize(1000); //1kHz
Timer1.pwm(9, 512); //50%