Last edited 02/08/2009
This was originally posted on the TeamPaulC blog, that blog entry will not be updated, but this page will be updated as required.
Thank you c.a. church for the great tutorial no how to get the TSL230R to interface with the Arduino. He did a great job showing how to interface and calculate the frequency. However, his approach required both an interrupt AND a separate poll of the results every second to calculate the frequency.
His approach is absolutely fine, but I would prefer to setup the interrupt and have it also do the frequency calculation every period of time and put the results into a volatile variable. That way I can start the interrupt, never worry about it again, and just read the frequency whenever I need it. To that end, find below a new version of his code, slightly rearranged and with a few new variables and output to the serial monitor for debugging.
If you are not going to use the light sensor, you can always call
to turn them off and back on. Just remember that the first time that freq is calculated after a call to interrupts() it will be bogus!