LED pulser

I want to use Arduino to made a LED pulser for 2 LEDs with following specifications:

  • 10 microsecond pulses at 100Hz
  • LEDs should be driven in a looped sequence

off on
LED1
LED2

LED1 LED2

LED1
LED2

  • the brighness of LED2 should be variable

Is that approach feasible using a Arduino Uno? Can you give me some hints or links?

Thank you!

I will not go into describing code (hint- you need the "micros()" function,) but given your specifications, you clearly cannot use PWM to control the LED brightness. The closest you might get would be to control the pulse duration, perhaps using a timer.

If you know how many steps of brightness you need, you can use more than one output pin to power the LED through different resistors in a binary representation.

Thanks!

In meantime I found a sketch in the Arduino cookbook which is very useful for my approach. This sketch employes the timer1 library. I wonder whether it is possible to add a second LED at different frequency and pulse duration to the code? Or is Timer1 limited to one LED?

Here is the sketch:

#include <TimerOne.h>
#define pwmRegister OCR1A // the logical pin, can be set to OCR1B

const int outPin = 9; // the physical pin
long period = 10000; // the period in microseconds
long pulseWidth = 1000; // width of a pulse in microseconds
int prescale[] = {0,1,8,64,256,1024}; // the range of prescale values

void setup()
{
Serial.begin(9600);
pinMode(outPin, OUTPUT);
Timer1.initialize(period); // initialize timer1, 1000 microseconds
setPulseWidth(pulseWidth);
}
void loop()
{

}
bool setPulseWidth(long microseconds)
{
bool ret = false;
int prescaleValue = prescale[Timer1.clockSelectBits];
// calculate time per counter tick in nanoseconds
long precision = (F_CPU / 128000) * prescaleValue ;
period = precision * ICR1 / 1000; // period in microseconds
if( microseconds < period)
{
int duty = map(microseconds, 0,period, 0,1024);
if( duty < 1)
duty = 1;
if(microseconds > 0 && duty < RESOLUTION)
{
Timer1.pwm(outPin, duty);
ret = true;
}
}
return ret;
}

Or is Timer1 limited to one LED?

second LED at different frequency

It is limited to one time.

However their is timer 2 to go at.