Measure nightsky with TSL237

GoForSmoke:
So you have used interrupts and know to make variables used in interrupts as volatile?
And you know that time is kept in unsigned long variables?

How long can you aim at dark sky to get measurements? 3 seconds? 30 s? 300 s? 30 minutes?

Maybe the best way will be to count pulses and see how long that takes.
....
You understand, if I stop when pulse count is done I can know how many whole usecs (microseconds) it takes but I can't know the fraction of a usec after the last full usec. If it was 400001.7 usecs, I will miss the .7. That is an unavoidable (and small) source of error.
If I stop on a time count while also counting pulses then I can know the usecs and how many pulses but not the fraction. If 100 seconds takes 50.8 pulses, my 100 second read only sees 50.
....
Since pulses are so big compared to usecs there will be more possible error counting over a set time than counting a set number of pulses and seeing how long that took. I would rather have a fraction of a usec (really, Arduino is good to 4 usecs which is still very small) as error than a fraction of a much bigger pulse as error.
What decides the method for me is the way with the smaller error. In this case, it's pretty clear?

So big open to the forum just to be sure question --- can you read micros() in an interrupt?

No i havenĀ“t really used interrupts more then those that allready have been written in existing code... I have read the reference about interrupts and there are two kinds? internal and external? the external ones are located on pin2 and 3 on the uno. Is one of those inputs usable for me?

I think 10sec will be the highest time i want to measure (the original SQM-meter measures on 2sec)

So 10000ms of measurements is a number i can start with.

I understand that i will lose the .x count of the pulses if the time runs out :slight_smile: