Counting frequency output from colour sensor

I’m using a TCS-3200 colour sensor. I want to count the number of square waves (or hi/lo changes) output on the TCS’s frequency pin in 1 second, expected frequency around 200,000.

The frequency of each square wave is proportional to light intensity at that moment so across square waves frequency can change, hence I want to count a sample, just just time the first.

Any help with code to count this output would be greatly appreciated.

You have several options. One is to use an internal timer to count the CPU clock ticks from one rising edge to the next (limited resolution at that high frequencies) or you can count the edges using an external interrupt. Just increasing a counter should be fast enough to keep up to the frequencies you expect.

For this kind of frequencies don't use an interrupt, use it as clock input for one of the counters (use TCNT1 on the Uno as it's the only 16-bit counter). Let it run for some time (10-100 ms or so, make sure it's a good number but won't overflow), then read back the counter. Barely any processor overhead.