This was only pointed out to me today, sorry for the very slow response.
I have a couple of points.
- The convention for header files is they should only contain information about code or data, and never generate code within itself. If a header file, which generates code or allocates space for data, gets included into several places (e.g. several .c or .cpp files), it will likely generate link errors because the same functions or data are defined multiple times.
(Macros are okay because they are expanded in the program which is including the header.)
It is better to put the code in a normal .c/.cpp/.pde file, and use the header to say what the function looks like.
So the header would only contain:
void cameraSnap(int pin);
The remainder of the file would be in a normal .pde/.c/.cpp file (I can't quickly say which, but I'd tend to do a .pde).
- Did you know that the hardware timers in the Arduino (ATmega) can generate square waves without continual software intervention?
There are three timers, and anyone will do the job needed.
By using a timer, the 38KHz modulation will be very accurate (sub-10th-microsecond), and the program can get on and do other things because it is not running in a loop to control the IR LED modulation. The program will need to control the larger scale timing (though that could hang off the same timer in an interrupt service routine if you really wanted to).
There is a downside though. You'd need to understand the ATmega manual chapter on the timer, and the set-up code looks a bit ugly, but it is rock solid.
PS - I am away for a few days, so if I don't respond quickly, I apologise in advance. I will try to get back to you later this week. If you want me to, I can help you write timer code.