Writing & Reading PWM at the same time.

Using IR LED's, Is there a way to (on the same arduino) to use analogWrite() on a pin, and then on another pin, read in how what the pwm is? I tried analogWrite() and analogRead() but that did not work as expected...

What I really want to do is tell that the sending IR led is at "45% duty cycle" by reading another pin -- the idea is to check to make sure that the IR signal being read is from "me" not another device and thought the this might be a way to go.

I don't see the point in doing this. You just set the PWM and that is it.
Do you understand that PWM is a digital signal that is on or off and it is the ratio of these times that is the duty cycle? That is why using an analog read is useless.

But if you do want to piss away your processing power then use the pulse in function to measure the PWM.

Thanks for the constructive help & criticism -- much appreciated.

Yes, should be possible. I have done this for fun & learning myself :slight_smile:

You need to write an interrupt function (ISR) to save the timesamps into a 'circular' array and process this in the main loop.

see http://www.arduino.cc/en/Reference/AttachInterrupt
...you will need to use the CHANGE option

As long as the frequency isnt too high, there should not be a problem with resources.

However, the usual way to check this is with an oscilloscope or DMM (with freq feature).

Thanks! That gives me something to go on...